Bug 1441308 - Split out document pieces of WebRenderLayerManager r=jrmuizel
authorDoug Thayer <dothayer@mozilla.com>
Mon, 07 Jan 2019 21:33:10 +0000
changeset 452767 ee870d4a43083769491e0964ae180304542fc10f
parent 452766 5b35ab00691e00766b0b686be6b8f9e5107e4beb
child 452768 27dc3484e7ef99a4f786fac1f9a5d29eb9de8498
push id75585
push userdothayer@mozilla.com
push dateMon, 07 Jan 2019 21:33:56 +0000
treeherderautoland@ee870d4a4308 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1441308
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1441308 - Split out document pieces of WebRenderLayerManager r=jrmuizel Per our discussion, this patch splits out the state management bits of WebRenderLayerManager, allowing for them to be maintained per-document. Differential Revision: https://phabricator.services.mozilla.com/D13577
gfx/layers/ipc/SharedSurfacesChild.cpp
gfx/layers/ipc/SharedSurfacesChild.h
gfx/layers/moz.build
gfx/layers/wr/RenderRootStateManager.cpp
gfx/layers/wr/RenderRootStateManager.h
gfx/layers/wr/WebRenderCanvasRenderer.cpp
gfx/layers/wr/WebRenderCanvasRenderer.h
gfx/layers/wr/WebRenderCommandBuilder.cpp
gfx/layers/wr/WebRenderCommandBuilder.h
gfx/layers/wr/WebRenderLayerManager.cpp
gfx/layers/wr/WebRenderLayerManager.h
gfx/layers/wr/WebRenderUserData.cpp
gfx/layers/wr/WebRenderUserData.h
gfx/src/nsITheme.h
gfx/thebes/gfxFontMissingGlyphs.cpp
gfx/webrender_bindings/WebRenderAPI.cpp
gfx/webrender_bindings/WebRenderAPI.h
layout/forms/nsButtonFrameRenderer.cpp
layout/forms/nsFieldSetFrame.cpp
layout/generic/TextDrawTarget.h
layout/generic/TextOverflow.cpp
layout/generic/nsBulletFrame.cpp
layout/generic/nsCanvasFrame.cpp
layout/generic/nsCanvasFrame.h
layout/generic/nsColumnSetFrame.cpp
layout/generic/nsFrame.cpp
layout/generic/nsHTMLCanvasFrame.cpp
layout/generic/nsImageFrame.cpp
layout/generic/nsImageFrame.h
layout/generic/nsPluginFrame.cpp
layout/generic/nsPluginFrame.h
layout/generic/nsTextFrame.cpp
layout/generic/nsVideoFrame.cpp
layout/ipc/RenderFrame.cpp
layout/ipc/RenderFrame.h
layout/mathml/nsMathMLmtableFrame.cpp
layout/painting/nsCSSRendering.cpp
layout/painting/nsCSSRendering.h
layout/painting/nsCSSRenderingBorders.cpp
layout/painting/nsCSSRenderingBorders.h
layout/painting/nsDisplayList.cpp
layout/painting/nsDisplayList.h
layout/painting/nsImageRenderer.cpp
layout/painting/nsImageRenderer.h
layout/tables/nsTableCellFrame.cpp
layout/tables/nsTableFrame.cpp
layout/xul/nsImageBoxFrame.cpp
layout/xul/nsImageBoxFrame.h
layout/xul/nsTextBoxFrame.cpp
widget/cocoa/nsNativeThemeCocoa.h
widget/cocoa/nsNativeThemeCocoa.mm
widget/gtk/nsNativeThemeGTK.cpp
widget/gtk/nsNativeThemeGTK.h
--- a/gfx/layers/ipc/SharedSurfacesChild.cpp
+++ b/gfx/layers/ipc/SharedSurfacesChild.cpp
@@ -4,30 +4,31 @@
  * 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 "SharedSurfacesChild.h"
 #include "SharedSurfacesParent.h"
 #include "CompositorManagerChild.h"
 #include "mozilla/gfx/gfxVars.h"
 #include "mozilla/image/RecyclingSourceSurface.h"
+#include "mozilla/layers/IpcResourceUpdateQueue.h"
 #include "mozilla/layers/SourceSurfaceSharedData.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
-#include "mozilla/layers/WebRenderLayerManager.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/SystemGroup.h"  // for SystemGroup
 
 namespace mozilla {
 namespace layers {
 
 using namespace mozilla::gfx;
 
 /* static */ UserDataKey SharedSurfacesChild::sSharedKey;
 
-SharedSurfacesChild::ImageKeyData::ImageKeyData(WebRenderLayerManager* aManager,
-                                                const wr::ImageKey& aImageKey)
+SharedSurfacesChild::ImageKeyData::ImageKeyData(
+    RenderRootStateManager* aManager, const wr::ImageKey& aImageKey)
     : mManager(aManager), mImageKey(aImageKey) {}
 
 SharedSurfacesChild::ImageKeyData::ImageKeyData(
     SharedSurfacesChild::ImageKeyData&& aOther)
     : mManager(std::move(aOther.mManager)),
       mDirtyRect(std::move(aOther.mDirtyRect)),
       mImageKey(aOther.mImageKey) {}
 
@@ -80,23 +81,23 @@ SharedSurfacesChild::SharedUserData::~Sh
       nsCOMPtr<nsIRunnable> task =
           new DestroyRunnable(mId, mShared, std::move(mKeys));
       SystemGroup::Dispatch(TaskCategory::Other, task.forget());
     }
   }
 }
 
 wr::ImageKey SharedSurfacesChild::SharedUserData::UpdateKey(
-    WebRenderLayerManager* aManager, wr::IpcResourceUpdateQueue& aResources,
+    RenderRootStateManager* aManager, wr::IpcResourceUpdateQueue& aResources,
     const Maybe<IntRect>& aDirtyRect) {
   MOZ_ASSERT(aManager);
   MOZ_ASSERT(!aManager->IsDestroyed());
 
   // We iterate through all of the items to ensure we clean up the old
-  // WebRenderLayerManager references. Most of the time there will be few
+  // RenderRootStateManager references. Most of the time there will be few
   // entries and this should not be particularly expensive compared to the
   // cost of duplicating image keys. In an ideal world, we would generate a
   // single key for the surface, and it would be usable on all of the
   // renderer instances. For now, we must allocate a key for each WR bridge.
   wr::ImageKey key;
   bool found = false;
   auto i = mKeys.Length();
   while (i > 0) {
@@ -281,17 +282,17 @@ SharedSurfacesChild::AsSourceSurfaceShar
     return;
   }
 
   SharedUserData* unused = nullptr;
   SharedSurfacesChild::ShareInternal(aSurface, &unused);
 }
 
 /* static */ nsresult SharedSurfacesChild::Share(
-    SourceSurfaceSharedData* aSurface, WebRenderLayerManager* aManager,
+    SourceSurfaceSharedData* aSurface, RenderRootStateManager* aManager,
     wr::IpcResourceUpdateQueue& aResources, wr::ImageKey& aKey) {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aSurface);
   MOZ_ASSERT(aManager);
 
   // Each time the surface changes, the producers of SourceSurfaceSharedData
   // surfaces promise to increment the invalidation counter each time the
   // surface has changed. We can use this counter to determine whether or not
@@ -303,17 +304,17 @@ SharedSurfacesChild::AsSourceSurfaceShar
     MOZ_ASSERT(data);
     aKey = data->UpdateKey(aManager, aResources, dirtyRect);
   }
 
   return rv;
 }
 
 /* static */ nsresult SharedSurfacesChild::Share(
-    ImageContainer* aContainer, WebRenderLayerManager* aManager,
+    ImageContainer* aContainer, RenderRootStateManager* aManager,
     wr::IpcResourceUpdateQueue& aResources, wr::ImageKey& aKey) {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aContainer);
   MOZ_ASSERT(aManager);
 
   if (aContainer->IsAsync()) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
@@ -434,17 +435,17 @@ SharedSurfacesChild::AsSourceSurfaceShar
   }
 
   SharedSurfacesAnimation* anim = aContainer->EnsureSharedSurfacesAnimation();
   MOZ_ASSERT(anim);
 
   return anim->SetCurrentFrame(aSurface, sharedSurface, aDirtyRect);
 }
 
-AnimationImageKeyData::AnimationImageKeyData(WebRenderLayerManager* aManager,
+AnimationImageKeyData::AnimationImageKeyData(RenderRootStateManager* aManager,
                                              const wr::ImageKey& aImageKey)
     : SharedSurfacesChild::ImageKeyData(aManager, aImageKey),
       mRecycling(false) {}
 
 AnimationImageKeyData::AnimationImageKeyData(AnimationImageKeyData&& aOther)
     : SharedSurfacesChild::ImageKeyData(std::move(aOther)),
       mPendingRelease(std::move(aOther.mPendingRelease)),
       mRecycling(aOther.mRecycling) {}
@@ -532,32 +533,32 @@ nsresult SharedSurfacesAnimation::SetCur
     }
   }
 
   return NS_OK;
 }
 
 nsresult SharedSurfacesAnimation::UpdateKey(
     SourceSurface* aParentSurface, SourceSurfaceSharedData* aSurface,
-    WebRenderLayerManager* aManager, wr::IpcResourceUpdateQueue& aResources,
+    RenderRootStateManager* aManager, wr::IpcResourceUpdateQueue& aResources,
     wr::ImageKey& aKey) {
   SharedSurfacesChild::SharedUserData* data = nullptr;
   nsresult rv = SharedSurfacesChild::ShareInternal(aSurface, &data);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   MOZ_ASSERT(data);
   if (mId.mHandle != data->Id().mHandle) {
     mKeys.Clear();
     mId = data->Id();
   }
 
   // We iterate through all of the items to ensure we clean up the old
-  // WebRenderLayerManager references. Most of the time there will be few
+  // RenderRootStateManager references. Most of the time there will be few
   // entries and this should not be particularly expensive compared to the
   // cost of duplicating image keys. In an ideal world, we would generate a
   // single key for the surface, and it would be usable on all of the
   // renderer instances. For now, we must allocate a key for each WR bridge.
   bool found = false;
   auto i = mKeys.Length();
   while (i > 0) {
     --i;
@@ -592,17 +593,17 @@ nsresult SharedSurfacesAnimation::Update
     mKeys.AppendElement(std::move(data));
     aResources.AddExternalImage(mId, aKey);
   }
 
   return NS_OK;
 }
 
 void SharedSurfacesAnimation::ReleasePreviousFrame(
-    WebRenderLayerManager* aManager, const wr::ExternalImageId& aId) {
+    RenderRootStateManager* aManager, const wr::ExternalImageId& aId) {
   MOZ_ASSERT(aManager);
 
   auto i = mKeys.Length();
   while (i > 0) {
     --i;
     AnimationImageKeyData& entry = mKeys[i];
     MOZ_ASSERT(!entry.mManager->IsDestroyed());
     if (entry.mManager == aManager) {
@@ -624,17 +625,17 @@ void SharedSurfacesAnimation::ReleasePre
       }
 
       entry.mPendingRelease.RemoveElementsAt(0, k + 1);
       break;
     }
   }
 }
 
-void SharedSurfacesAnimation::Invalidate(WebRenderLayerManager* aManager) {
+void SharedSurfacesAnimation::Invalidate(RenderRootStateManager* aManager) {
   auto i = mKeys.Length();
   while (i > 0) {
     --i;
     AnimationImageKeyData& entry = mKeys[i];
     if (entry.mManager == aManager) {
       mKeys.RemoveElementAt(i);
       break;
     }
--- a/gfx/layers/ipc/SharedSurfacesChild.h
+++ b/gfx/layers/ipc/SharedSurfacesChild.h
@@ -36,17 +36,17 @@ class SourceSurfaceSharedData;
 namespace wr {
 class IpcResourceUpdateQueue;
 }  // namespace wr
 
 namespace layers {
 
 class CompositorManagerChild;
 class ImageContainer;
-class WebRenderLayerManager;
+class RenderRootStateManager;
 
 class SharedSurfacesChild final {
  public:
   /**
    * Request that the surface be mapped into the compositor thread's memory
    * space. This is useful for when the caller itself has no present need for
    * the surface to be mapped, but knows there will be such a need in the
    * future. This may be called from any thread, but it may cause a dispatch to
@@ -62,29 +62,29 @@ class SharedSurfacesChild final {
   static nsresult Share(gfx::SourceSurface* aSurface, wr::ExternalImageId& aId);
 
   /**
    * Request that the surface be mapped into the compositor thread's memory
    * space, and a valid ImageKey be generated for it for use with WebRender.
    * This must be called from the main thread.
    */
   static nsresult Share(gfx::SourceSurfaceSharedData* aSurface,
-                        WebRenderLayerManager* aManager,
+                        RenderRootStateManager* aManager,
                         wr::IpcResourceUpdateQueue& aResources,
                         wr::ImageKey& aKey);
 
   /**
    * Request that the first surface in the image container's current images be
    * mapped into the compositor thread's memory space, and a valid ImageKey be
    * generated for it for use with WebRender. If a different method should be
    * used to share the image data for this particular container, it will return
    * NS_ERROR_NOT_IMPLEMENTED. This must be called from the main thread.
    */
   static nsresult Share(ImageContainer* aContainer,
-                        WebRenderLayerManager* aManager,
+                        RenderRootStateManager* aManager,
                         wr::IpcResourceUpdateQueue& aResources,
                         wr::ImageKey& aKey);
 
   /**
    * Get the external ID, if any, bound to the shared surface. Used for memory
    * reporting purposes.
    */
   static Maybe<wr::ExternalImageId> GetExternalId(
@@ -98,30 +98,30 @@ class SharedSurfacesChild final {
       gfx::SourceSurface* aSurface);
 
   static nsresult UpdateAnimation(ImageContainer* aContainer,
                                   gfx::SourceSurface* aSurface,
                                   const gfx::IntRect& aDirtyRect);
 
   class ImageKeyData {
    public:
-    ImageKeyData(WebRenderLayerManager* aManager,
+    ImageKeyData(RenderRootStateManager* aManager,
                  const wr::ImageKey& aImageKey);
     ~ImageKeyData();
 
     ImageKeyData(ImageKeyData&& aOther);
     ImageKeyData& operator=(ImageKeyData&& aOther);
     ImageKeyData(const ImageKeyData&) = delete;
     ImageKeyData& operator=(const ImageKeyData&) = delete;
 
     void MergeDirtyRect(const Maybe<gfx::IntRect>& aDirtyRect);
 
     Maybe<gfx::IntRect> TakeDirtyRect() { return std::move(mDirtyRect); }
 
-    RefPtr<WebRenderLayerManager> mManager;
+    RefPtr<RenderRootStateManager> mManager;
     Maybe<gfx::IntRect> mDirtyRect;
     wr::ImageKey mImageKey;
   };
 
  private:
   SharedSurfacesChild() = delete;
   ~SharedSurfacesChild() = delete;
 
@@ -152,17 +152,17 @@ class SharedSurfacesChild final {
 
     bool IsShared() const { return mShared; }
 
     void MarkShared() {
       MOZ_ASSERT(!mShared);
       mShared = true;
     }
 
-    wr::ImageKey UpdateKey(WebRenderLayerManager* aManager,
+    wr::ImageKey UpdateKey(RenderRootStateManager* aManager,
                            wr::IpcResourceUpdateQueue& aResources,
                            const Maybe<gfx::IntRect>& aDirtyRect);
 
    protected:
     AutoTArray<ImageKeyData, 1> mKeys;
     wr::ExternalImageId mId;
     bool mShared : 1;
   };
@@ -175,17 +175,17 @@ class SharedSurfacesChild final {
 
   static void DestroySharedUserData(void* aClosure);
 
   static gfx::UserDataKey sSharedKey;
 };
 
 class AnimationImageKeyData final : public SharedSurfacesChild::ImageKeyData {
  public:
-  AnimationImageKeyData(WebRenderLayerManager* aManager,
+  AnimationImageKeyData(RenderRootStateManager* aManager,
                         const wr::ImageKey& aImageKey);
 
   ~AnimationImageKeyData();
 
   AnimationImageKeyData(AnimationImageKeyData&& aOther);
   AnimationImageKeyData& operator=(AnimationImageKeyData&& aOther);
 
   AutoTArray<RefPtr<gfx::SourceSurface>, 2> mPendingRelease;
@@ -224,32 +224,32 @@ class SharedSurfacesAnimation final {
    *                       or it may be a wrapper surface such as
    *                       RecyclingSourceSurface.
    * @param aSurface  The current frame. This should match what was cached via
    *                  SetCurrentFrame, but if it does not, it will need to
    *                  regenerate the cached ImageKey.
    */
   nsresult UpdateKey(gfx::SourceSurface* aParentSurface,
                      gfx::SourceSurfaceSharedData* aSurface,
-                     WebRenderLayerManager* aManager,
+                     RenderRootStateManager* aManager,
                      wr::IpcResourceUpdateQueue& aResources,
                      wr::ImageKey& aKey);
 
   /**
    * Release our reference to all frames up to and including the frame which
    * has an external image ID which matches aId.
    */
-  void ReleasePreviousFrame(WebRenderLayerManager* aManager,
+  void ReleasePreviousFrame(RenderRootStateManager* aManager,
                             const wr::ExternalImageId& aId);
 
   /**
    * Destroy any state information bound for the given layer manager. Any
    * image keys are already invalid.
    */
-  void Invalidate(WebRenderLayerManager* aManager);
+  void Invalidate(RenderRootStateManager* aManager);
 
  private:
   ~SharedSurfacesAnimation();
 
   void HoldSurfaceForRecycling(AnimationImageKeyData& aEntry,
                                gfx::SourceSurface* aParentSurface,
                                gfx::SourceSurfaceSharedData* aSurface);
 
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -236,16 +236,17 @@ EXPORTS.mozilla.layers += [
     'SyncObject.h',
     'TextureSourceProvider.h',
     'TextureWrapperImage.h',
     'TransactionIdAllocator.h',
     'UpdateImageHelper.h',
     'wr/AsyncImagePipelineManager.h',
     'wr/ClipManager.h',
     'wr/IpcResourceUpdateQueue.h',
+    'wr/RenderRootStateManager.h',
     'wr/StackingContextHelper.h',
     'wr/WebRenderBridgeChild.h',
     'wr/WebRenderBridgeParent.h',
     'wr/WebRenderCanvasRenderer.h',
     'wr/WebRenderCommandBuilder.h',
     'wr/WebRenderDrawEventRecorder.h',
     'wr/WebRenderImageHost.h',
     'wr/WebRenderLayerManager.h',
@@ -480,16 +481,17 @@ UNIFIED_SOURCES += [
     'SourceSurfaceSharedData.cpp',
     'SourceSurfaceVolatileData.cpp',
     'SyncObject.cpp',
     'TextureSourceProvider.cpp',
     'TextureWrapperImage.cpp',
     'wr/AsyncImagePipelineManager.cpp',
     'wr/ClipManager.cpp',
     'wr/IpcResourceUpdateQueue.cpp',
+    'wr/RenderRootStateManager.cpp',
     'wr/StackingContextHelper.cpp',
     'wr/WebRenderBridgeChild.cpp',
     'wr/WebRenderBridgeParent.cpp',
     'wr/WebRenderCanvasRenderer.cpp',
     'wr/WebRenderCommandBuilder.cpp',
     'wr/WebRenderDrawEventRecorder.cpp',
     'wr/WebRenderImageHost.cpp',
     'wr/WebRenderLayerManager.cpp',
new file mode 100644
--- /dev/null
+++ b/gfx/layers/wr/RenderRootStateManager.cpp
@@ -0,0 +1,276 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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 "mozilla/layers/RenderRootStateManager.h"
+
+#include "mozilla/layers/WebRenderBridgeChild.h"
+
+namespace mozilla {
+namespace layers {
+
+RenderRootStateManager::RenderRootStateManager(WebRenderLayerManager* aLayerManager)
+  : mLayerManager(aLayerManager)
+  , mDestroyed(false)
+{
+}
+
+RenderRootStateManager::~RenderRootStateManager()
+{}
+
+// RenderRootStateManager shares its ref count with the WebRenderLayerManager that
+// created it. You can think of the two classes as being one unit, except there
+// are multiple RenderRootStateManagers per WebRenderLayerManager. Since we need
+// to reference the WebRenderLayerManager and it needs to reference us, this
+// avoids us needing to involve the cycle collector.
+void
+RenderRootStateManager::AddRef()
+{
+  mLayerManager->AddRef();
+}
+
+void
+RenderRootStateManager::Release()
+{
+  mLayerManager->Release();
+}
+
+
+WebRenderBridgeChild*
+RenderRootStateManager::WrBridge() const
+{
+  return mLayerManager->WrBridge();
+}
+
+WebRenderCommandBuilder&
+RenderRootStateManager::CommandBuilder()
+{
+  return mLayerManager->CommandBuilder();
+}
+
+RenderRootStateManager::WebRenderUserDataRefTable*
+RenderRootStateManager::GetWebRenderUserDataTable()
+{
+  return mLayerManager->GetWebRenderUserDataTable();
+}
+
+wr::IpcResourceUpdateQueue&
+RenderRootStateManager::AsyncResourceUpdates()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  if (!mAsyncResourceUpdates) {
+    mAsyncResourceUpdates.emplace(WrBridge());
+
+    RefPtr<Runnable> task = NewRunnableMethod(
+      "RenderRootStateManager::FlushAsyncResourceUpdates",
+      this, &RenderRootStateManager::FlushAsyncResourceUpdates);
+    NS_DispatchToMainThread(task.forget());
+  }
+
+  return mAsyncResourceUpdates.ref();
+}
+
+void
+RenderRootStateManager::Destroy()
+{
+  ClearAsyncAnimations();
+
+  if (WrBridge()) {
+    // Just clear ImageKeys, they are deleted during WebRenderAPI destruction.
+    DiscardLocalImages();
+    // CompositorAnimations are cleared by WebRenderBridgeParent.
+    mDiscardedCompositorAnimationsIds.Clear();
+  }
+
+  mActiveCompositorAnimationIds.clear();
+
+  mDestroyed = true;
+}
+
+void
+RenderRootStateManager::FlushAsyncResourceUpdates()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  if (!mAsyncResourceUpdates) {
+    return;
+  }
+
+  if (!IsDestroyed() && WrBridge()) {
+    WrBridge()->UpdateResources(mAsyncResourceUpdates.ref());
+  }
+
+  mAsyncResourceUpdates.reset();
+}
+
+void
+RenderRootStateManager::AddImageKeyForDiscard(wr::ImageKey key)
+{
+  mImageKeysToDelete.AppendElement(key);
+}
+
+void
+RenderRootStateManager::AddBlobImageKeyForDiscard(wr::BlobImageKey key)
+{
+  mBlobImageKeysToDelete.AppendElement(key);
+}
+
+void
+RenderRootStateManager::DiscardImagesInTransaction(wr::IpcResourceUpdateQueue& aResources)
+{
+  for (const auto& key : mImageKeysToDelete) {
+    aResources.DeleteImage(key);
+  }
+  for (const auto& key : mBlobImageKeysToDelete) {
+    aResources.DeleteBlobImage(key);
+  }
+  mImageKeysToDelete.Clear();
+  mBlobImageKeysToDelete.Clear();
+}
+
+void
+RenderRootStateManager::DiscardLocalImages()
+{
+  // Removes images but doesn't tell the parent side about them
+  // This is useful in empty / failed transactions where we created
+  // image keys but didn't tell the parent about them yet.
+  mImageKeysToDelete.Clear();
+  mBlobImageKeysToDelete.Clear();
+}
+
+void
+RenderRootStateManager::ClearCachedResources()
+{
+  mActiveCompositorAnimationIds.clear();
+  mDiscardedCompositorAnimationsIds.Clear();
+}
+
+void
+RenderRootStateManager::AddActiveCompositorAnimationId(uint64_t aId)
+{
+  // In layers-free mode we track the active compositor animation ids on the
+  // client side so that we don't try to discard the same animation id multiple
+  // times. We could just ignore the multiple-discard on the parent side, but
+  // checking on the content side reduces IPC traffic.
+  mActiveCompositorAnimationIds.insert(aId);
+}
+
+void
+RenderRootStateManager::AddCompositorAnimationsIdForDiscard(uint64_t aId)
+{
+  if (mActiveCompositorAnimationIds.erase(aId)) {
+    // For layers-free ensure we don't try to discard an animation id that wasn't
+    // active. We also remove it from mActiveCompositorAnimationIds so we don't
+    // discard it again unless it gets re-activated.
+    mDiscardedCompositorAnimationsIds.AppendElement(aId);
+  }
+}
+
+void
+RenderRootStateManager::DiscardCompositorAnimations()
+{
+  if (WrBridge()->IPCOpen() &&
+      !mDiscardedCompositorAnimationsIds.IsEmpty()) {
+    WrBridge()->
+      SendDeleteCompositorAnimations(mDiscardedCompositorAnimationsIds);
+  }
+  mDiscardedCompositorAnimationsIds.Clear();
+}
+
+void
+RenderRootStateManager::RegisterAsyncAnimation(const wr::ImageKey& aKey,
+                                              SharedSurfacesAnimation* aAnimation)
+{
+  mAsyncAnimations.insert(std::make_pair(wr::AsUint64(aKey), aAnimation));
+}
+
+void
+RenderRootStateManager::DeregisterAsyncAnimation(const wr::ImageKey& aKey)
+{
+  mAsyncAnimations.erase(wr::AsUint64(aKey));
+}
+
+void
+RenderRootStateManager::ClearAsyncAnimations()
+{
+  for (const auto& i : mAsyncAnimations) {
+    i.second->Invalidate(this);
+  }
+  mAsyncAnimations.clear();
+}
+
+void
+RenderRootStateManager::WrReleasedImages(const nsTArray<wr::ExternalImageKeyPair>& aPairs)
+{
+  // A SharedSurfaceAnimation object's lifetime is tied to its owning
+  // ImageContainer. When the ImageContainer is released,
+  // SharedSurfaceAnimation::Destroy is called which should ensure it is removed
+  // from the layer manager. Whenever the namespace for the
+  // WebRenderLayerManager itself is invalidated (e.g. we changed windows, or
+  // were destroyed ourselves), we callback into the SharedSurfaceAnimation
+  // object to remove its image key for us and any bound surfaces. If, for any
+  // reason, we somehow missed an WrReleasedImages call before the animation
+  // was bound to the layer manager, it will free those associated surfaces on
+  // the next ReleasePreviousFrame call.
+  for (const auto& pair : aPairs) {
+    auto i = mAsyncAnimations.find(wr::AsUint64(pair.key));
+    if (i != mAsyncAnimations.end()) {
+      i->second->ReleasePreviousFrame(this, pair.id);
+    }
+  }
+}
+
+void
+RenderRootStateManager::AddWebRenderParentCommand(const WebRenderParentCommand& aCmd)
+{
+  WrBridge()->AddWebRenderParentCommand(aCmd);
+}
+void
+RenderRootStateManager::UpdateResources(wr::IpcResourceUpdateQueue& aResources)
+{
+  WrBridge()->UpdateResources(aResources);
+}
+void
+RenderRootStateManager::AddPipelineIdForAsyncCompositable(const wr::PipelineId& aPipelineId,
+                                                   const CompositableHandle& aHandle)
+{
+  WrBridge()->AddPipelineIdForAsyncCompositable(aPipelineId, aHandle);
+}
+void
+RenderRootStateManager::AddPipelineIdForCompositable(const wr::PipelineId& aPipelineId,
+                                              const CompositableHandle& aHandle)
+{
+  WrBridge()->AddPipelineIdForCompositable(aPipelineId, aHandle);
+}
+void
+RenderRootStateManager::RemovePipelineIdForCompositable(const wr::PipelineId& aPipelineId)
+{
+  WrBridge()->RemovePipelineIdForCompositable(aPipelineId);
+}
+  /// Release TextureClient that is bounded to ImageKey.
+  /// It is used for recycling TextureClient.
+void
+RenderRootStateManager::ReleaseTextureOfImage(const wr::ImageKey& aKey)
+{
+  WrBridge()->ReleaseTextureOfImage(aKey);
+}
+
+wr::FontInstanceKey
+RenderRootStateManager::GetFontKeyForScaledFont(gfx::ScaledFont* aScaledFont,
+                                              wr::IpcResourceUpdateQueue* aResources)
+{
+  return WrBridge()->GetFontKeyForScaledFont(aScaledFont, aResources);
+}
+
+wr::FontKey
+RenderRootStateManager::GetFontKeyForUnscaledFont(gfx::UnscaledFont* aUnscaledFont,
+                                                wr::IpcResourceUpdateQueue* aResources)
+{
+  return WrBridge()->GetFontKeyForUnscaledFont(aUnscaledFont, aResources);
+}
+
+} // namespace layers
+} // namespace mozilla
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/gfx/layers/wr/RenderRootStateManager.h
@@ -0,0 +1,98 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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 GFX_RENDERROOTSTATEMANAGER_H
+#define GFX_RENDERROOTSTATEMANAGER_H
+
+#include "mozilla/webrender/WebRenderAPI.h"
+
+#include "mozilla/layers/IpcResourceUpdateQueue.h"
+#include "mozilla/layers/WebRenderCommandBuilder.h"
+
+namespace mozilla {
+
+namespace layers {
+
+class RenderRootStateManager
+{
+  typedef nsTHashtable<nsRefPtrHashKey<WebRenderUserData>> WebRenderUserDataRefTable;
+
+public:
+  void AddRef();
+  void Release();
+
+  explicit RenderRootStateManager(WebRenderLayerManager* aLayerManager);
+
+  void Destroy();
+  bool IsDestroyed() { return mDestroyed; }
+  wr::IpcResourceUpdateQueue& AsyncResourceUpdates();
+  WebRenderBridgeChild* WrBridge() const;
+  WebRenderCommandBuilder& CommandBuilder();
+  WebRenderUserDataRefTable* GetWebRenderUserDataTable();
+  WebRenderLayerManager* LayerManager()
+  {
+    return mLayerManager;
+  }
+
+  void AddImageKeyForDiscard(wr::ImageKey key);
+  void AddBlobImageKeyForDiscard(wr::BlobImageKey key);
+  void DiscardImagesInTransaction(wr::IpcResourceUpdateQueue& aResources);
+  void DiscardLocalImages();
+
+  void ClearCachedResources();
+
+  // Methods to manage the compositor animation ids. Active animations are still
+  // going, and when they end we discard them and remove them from the active
+  // list.
+  void AddActiveCompositorAnimationId(uint64_t aId);
+  void AddCompositorAnimationsIdForDiscard(uint64_t aId);
+  void DiscardCompositorAnimations();
+
+  void RegisterAsyncAnimation(const wr::ImageKey& aKey, SharedSurfacesAnimation* aAnimation);
+  void DeregisterAsyncAnimation(const wr::ImageKey& aKey);
+  void ClearAsyncAnimations();
+  void WrReleasedImages(const nsTArray<wr::ExternalImageKeyPair>& aPairs);
+
+  void AddWebRenderParentCommand(const WebRenderParentCommand& aCmd);
+  void UpdateResources(wr::IpcResourceUpdateQueue& aResources);
+  void AddPipelineIdForAsyncCompositable(const wr::PipelineId& aPipelineId,
+                                         const CompositableHandle& aHandlee);
+  void AddPipelineIdForCompositable(const wr::PipelineId& aPipelineId,
+                                    const CompositableHandle& aHandlee);
+  void RemovePipelineIdForCompositable(const wr::PipelineId& aPipelineId);
+  /// Release TextureClient that is bounded to ImageKey.
+  /// It is used for recycling TextureClient.
+  void ReleaseTextureOfImage(const wr::ImageKey& aKey);
+  wr::FontInstanceKey GetFontKeyForScaledFont(gfx::ScaledFont* aScaledFont,
+                                              wr::IpcResourceUpdateQueue* aResources = nullptr);
+  wr::FontKey GetFontKeyForUnscaledFont(gfx::UnscaledFont* aUnscaledFont,
+                                        wr::IpcResourceUpdateQueue* aResources = nullptr);
+
+  void FlushAsyncResourceUpdates();
+private:
+  ~RenderRootStateManager();
+  WebRenderLayerManager* mLayerManager;
+  Maybe<wr::IpcResourceUpdateQueue> mAsyncResourceUpdates;
+  nsTArray<wr::ImageKey> mImageKeysToDelete;
+  nsTArray<wr::BlobImageKey> mBlobImageKeysToDelete;
+  std::unordered_map<uint64_t, RefPtr<SharedSurfacesAnimation>> mAsyncAnimations;
+
+  // Set of compositor animation ids for which there are active animations (as
+  // of the last transaction) on the compositor side.
+  std::unordered_set<uint64_t> mActiveCompositorAnimationIds;
+  // Compositor animation ids for animations that are done now and that we want
+  // the compositor to discard information for.
+  nsTArray<uint64_t> mDiscardedCompositorAnimationsIds;
+
+  bool mDestroyed;
+
+  friend class WebRenderLayerManager;
+};
+
+} // namespace layers
+} // namespace mozilla
+
+#endif /* GFX_RENDERROOTSTATEMANAGER_H */
--- a/gfx/layers/wr/WebRenderCanvasRenderer.cpp
+++ b/gfx/layers/wr/WebRenderCanvasRenderer.cpp
@@ -6,17 +6,17 @@
 
 #include "WebRenderCanvasRenderer.h"
 
 #include "GLContext.h"
 #include "GLScreenBuffer.h"
 #include "mozilla/layers/CompositorBridgeChild.h"
 #include "SharedSurfaceGL.h"
 #include "WebRenderBridgeChild.h"
-#include "WebRenderLayerManager.h"
+#include "RenderRootStateManager.h"
 
 namespace mozilla {
 namespace layers {
 
 CompositableForwarder* WebRenderCanvasRenderer::GetForwarder() {
   return mManager->WrBridge();
 }
 
@@ -26,17 +26,17 @@ void WebRenderCanvasRenderer::Initialize
 
 WebRenderCanvasRendererAsync::~WebRenderCanvasRendererAsync() { Destroy(); }
 
 void WebRenderCanvasRendererAsync::Initialize(
     const CanvasInitializeData& aData) {
   WebRenderCanvasRenderer::Initialize(aData);
 
   if (mPipelineId.isSome()) {
-    mManager->WrBridge()->RemovePipelineIdForCompositable(mPipelineId.ref());
+    mManager->RemovePipelineIdForCompositable(mPipelineId.ref());
     mPipelineId.reset();
   }
 }
 
 bool WebRenderCanvasRendererAsync::CreateCompositable() {
   if (!mCanvasClient) {
     TextureFlags flags = TextureFlags::DEFAULT;
     if (mOriginPos == gl::OriginPos::BottomLeft) {
@@ -55,45 +55,45 @@ bool WebRenderCanvasRendererAsync::Creat
 
     mCanvasClient->Connect();
   }
 
   if (!mPipelineId) {
     // Alloc async image pipeline id.
     mPipelineId = Some(
         mManager->WrBridge()->GetCompositorBridgeChild()->GetNextPipelineId());
-    mManager->WrBridge()->AddPipelineIdForCompositable(
-        mPipelineId.ref(), mCanvasClient->GetIPCHandle());
+    mManager->AddPipelineIdForCompositable(mPipelineId.ref(),
+                                           mCanvasClient->GetIPCHandle());
   }
 
   return true;
 }
 
 void WebRenderCanvasRendererAsync::ClearCachedResources() {
   if (mPipelineId.isSome()) {
-    mManager->WrBridge()->RemovePipelineIdForCompositable(mPipelineId.ref());
+    mManager->RemovePipelineIdForCompositable(mPipelineId.ref());
     mPipelineId.reset();
   }
 }
 
 void WebRenderCanvasRendererAsync::Destroy() {
   if (mPipelineId.isSome()) {
-    mManager->WrBridge()->RemovePipelineIdForCompositable(mPipelineId.ref());
+    mManager->RemovePipelineIdForCompositable(mPipelineId.ref());
     mPipelineId.reset();
   }
 }
 
 void WebRenderCanvasRendererAsync::
     UpdateCompositableClientForEmptyTransaction() {
   UpdateCompositableClient();
   if (mPipelineId.isSome()) {
     // Notify an update of async image pipeline during empty transaction.
     // During non empty transaction, WebRenderBridgeParent receives
     // OpUpdateAsyncImagePipeline message, but during empty transaction, the
     // message is not sent to WebRenderBridgeParent. Then
     // OpUpdatedAsyncImagePipeline is used to notify the update.
-    mManager->WrBridge()->AddWebRenderParentCommand(
+    mManager->AddWebRenderParentCommand(
         OpUpdatedAsyncImagePipeline(mPipelineId.ref()));
   }
 }
 
 }  // namespace layers
 }  // namespace mozilla
--- a/gfx/layers/wr/WebRenderCanvasRenderer.h
+++ b/gfx/layers/wr/WebRenderCanvasRenderer.h
@@ -7,34 +7,34 @@
 #ifndef GFX_WEBRENDERCANVASRENDERER_H
 #define GFX_WEBRENDERCANVASRENDERER_H
 
 #include "ShareableCanvasRenderer.h"
 
 namespace mozilla {
 namespace layers {
 
-class WebRenderLayerManager;
+class RenderRootStateManager;
 
 class WebRenderCanvasRenderer : public ShareableCanvasRenderer {
  public:
-  explicit WebRenderCanvasRenderer(WebRenderLayerManager* aManager)
+  explicit WebRenderCanvasRenderer(RenderRootStateManager* aManager)
       : mManager(aManager) {}
 
   void Initialize(const CanvasInitializeData& aData) override;
 
   CompositableForwarder* GetForwarder() override;
 
  protected:
-  WebRenderLayerManager* mManager;
+  RenderRootStateManager* mManager;
 };
 
 class WebRenderCanvasRendererAsync : public WebRenderCanvasRenderer {
  public:
-  explicit WebRenderCanvasRendererAsync(WebRenderLayerManager* aManager)
+  explicit WebRenderCanvasRendererAsync(RenderRootStateManager* aManager)
       : WebRenderCanvasRenderer(aManager) {}
   virtual ~WebRenderCanvasRendererAsync();
 
   WebRenderCanvasRendererAsync* AsWebRenderCanvasRendererAsync() override {
     return this;
   }
 
   void Initialize(const CanvasInitializeData& aData) override;
--- a/gfx/layers/wr/WebRenderCommandBuilder.cpp
+++ b/gfx/layers/wr/WebRenderCommandBuilder.cpp
@@ -8,16 +8,17 @@
 
 #include "BasicLayers.h"
 #include "mozilla/AutoRestore.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/Logging.h"
 #include "mozilla/gfx/Types.h"
 #include "mozilla/layers/ClipManager.h"
 #include "mozilla/layers/ImageClient.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
 #include "mozilla/layers/WebRenderLayerManager.h"
 #include "mozilla/layers/IpcResourceUpdateQueue.h"
 #include "mozilla/layers/SharedSurfacesChild.h"
 #include "mozilla/layers/SourceSurfaceSharedData.h"
 #include "mozilla/layers/StackingContextHelper.h"
 #include "mozilla/layers/UpdateImageHelper.h"
 #include "mozilla/layers/WebRenderDrawEventRecorder.h"
@@ -174,17 +175,17 @@ static void DestroyBlobGroupDataProperty
     item->mFrame = nullptr;
   }
   delete aArray;
 }
 
 static void TakeExternalSurfaces(
     WebRenderDrawEventRecorder* aRecorder,
     std::vector<RefPtr<SourceSurface>>& aExternalSurfaces,
-    WebRenderLayerManager* aManager, wr::IpcResourceUpdateQueue& aResources) {
+    RenderRootStateManager* aManager, wr::IpcResourceUpdateQueue& aResources) {
   aRecorder->TakeExternalSurfaces(aExternalSurfaces);
 
   for (auto& surface : aExternalSurfaces) {
     if (surface->GetType() != SurfaceType::DATA_SHARED) {
       MOZ_ASSERT_UNREACHABLE("External surface that is not a shared surface!");
       continue;
     }
 
@@ -349,17 +350,17 @@ struct DIGroup {
     for (auto iter = mDisplayItems.Iter(); !iter.Done(); iter.Next()) {
       BlobItemData* data = iter.Get()->GetKey();
       GP("Deleting %p-%d\n", data->mFrame, data->mDisplayItemKey);
       iter.Remove();
       delete data;
     }
   }
 
-  void ClearImageKey(WebRenderLayerManager* aManager, bool aForce = false) {
+  void ClearImageKey(RenderRootStateManager* aManager, bool aForce = false) {
     if (mKey) {
       MOZ_RELEASE_ASSERT(aForce || mInvalidRect.IsEmpty());
       aManager->AddBlobImageKeyForDiscard(mKey.value());
       mKey = Nothing();
     }
     mFonts.clear();
   }
 
@@ -708,28 +709,29 @@ struct DIGroup {
     context->SetMatrix(Matrix::Scaling(mScale.width, mScale.height)
                            .PreTranslate(-bounds.x, -bounds.y));
 
     GP("mInvalidRect: %d %d %d %d\n", mInvalidRect.x, mInvalidRect.y,
        mInvalidRect.width, mInvalidRect.height);
 
     bool empty = aStartItem == aEndItem;
     if (empty) {
-      ClearImageKey(aWrManager, true);
+      ClearImageKey(aWrManager->GetRenderRootStateManager(), true);
       return;
     }
 
     PaintItemRange(aGrouper, aStartItem, aEndItem, context, recorder);
 
     // XXX: set this correctly perhaps using
     // aItem->GetOpaqueRegion(aDisplayListBuilder, &snapped).
     //   Contains(paintBounds);?
     wr::OpacityType opacity = wr::OpacityType::HasAlphaChannel;
 
-    TakeExternalSurfaces(recorder, mExternalSurfaces, aWrManager, aResources);
+    TakeExternalSurfaces(recorder, mExternalSurfaces,
+                         aWrManager->GetRenderRootStateManager(), aResources);
     bool hasItems = recorder->Finish();
     GP("%d Finish\n", hasItems);
     Range<uint8_t> bytes((uint8_t*)recorder->mOutputStream.mData,
                          recorder->mOutputStream.mLength);
     if (!mKey) {
       if (!hasItems)  // we don't want to send a new image that doesn't have any
                       // items in it
         return;
@@ -1032,17 +1034,17 @@ void Grouper::PaintContainerItem(DIGroup
       aGroup->PaintItemRange(this, aChildren->GetBottom(), nullptr, aContext,
                              aRecorder);
       break;
   }
 }
 
 class WebRenderGroupData : public WebRenderUserData {
  public:
-  explicit WebRenderGroupData(WebRenderLayerManager* aWRManager,
+  explicit WebRenderGroupData(RenderRootStateManager* aWRManager,
                               nsDisplayItem* aItem);
   virtual ~WebRenderGroupData();
 
   virtual WebRenderGroupData* AsGroupData() override { return this; }
   virtual UserDataType GetType() override { return UserDataType::eGroup; }
   static UserDataType Type() { return UserDataType::eGroup; }
 
   DIGroup mSubGroup;
@@ -1123,19 +1125,20 @@ void Grouper::ConstructGroups(nsDisplayL
     if (IsItemProbablyActive(item, mDisplayListBuilder)) {
       currentGroup->EndGroup(aCommandBuilder->mManager, aDisplayListBuilder,
                              aBuilder, aResources, this, startOfCurrentGroup,
                              item);
       mClipManager.BeginItem(item, aSc);
       sIndent++;
       // Note: this call to CreateWebRenderCommands can recurse back into
       // this function.
+      RenderRootStateManager* manager =
+          aCommandBuilder->mManager->GetRenderRootStateManager();
       bool createdWRCommands = item->CreateWebRenderCommands(
-          aBuilder, aResources, aSc, aCommandBuilder->mManager,
-          mDisplayListBuilder);
+          aBuilder, aResources, aSc, manager, mDisplayListBuilder);
       sIndent--;
       MOZ_RELEASE_ASSERT(createdWRCommands,
                          "active transforms should always succeed at creating "
                          "WebRender commands");
 
       RefPtr<WebRenderGroupData> groupData =
           aCommandBuilder->CreateOrRecycleWebRenderUserData<WebRenderGroupData>(
               item);
@@ -1156,17 +1159,18 @@ void Grouper::ConstructGroups(nsDisplayL
             currentGroup->mAppUnitsPerDevPixel) {
           GP("app unit change following: %d %d\n",
              groupData->mFollowingGroup.mAppUnitsPerDevPixel,
              currentGroup->mAppUnitsPerDevPixel);
         }
         // The group changed size
         GP("Inner group size change\n");
         groupData->mFollowingGroup.ClearItems();
-        groupData->mFollowingGroup.ClearImageKey(aCommandBuilder->mManager);
+        groupData->mFollowingGroup.ClearImageKey(
+            aCommandBuilder->mManager->GetRenderRootStateManager());
       }
       groupData->mFollowingGroup.mGroupBounds = currentGroup->mGroupBounds;
       groupData->mFollowingGroup.mAppUnitsPerDevPixel =
           currentGroup->mAppUnitsPerDevPixel;
       groupData->mFollowingGroup.mLayerBounds = currentGroup->mLayerBounds;
       groupData->mFollowingGroup.mImageBounds = currentGroup->mImageBounds;
       groupData->mFollowingGroup.mScale = currentGroup->mScale;
       groupData->mFollowingGroup.mResidualOffset =
@@ -1293,16 +1297,20 @@ static mozilla::gfx::IntRect ScaleToOuts
           aOffset.x),
       NSToIntCeil(
           NSAppUnitsToFloatPixels(aRect.YMost(), float(aAppUnitsPerPixel)) *
               aYScale +
           aOffset.y));
   return rect;
 }
 
+RenderRootStateManager* WebRenderCommandBuilder::GetRenderRootStateManager() {
+  return mManager->GetRenderRootStateManager();
+}
+
 void WebRenderCommandBuilder::DoGroupingForDisplayList(
     nsDisplayList* aList, nsDisplayItem* aWrappingItem,
     nsDisplayListBuilder* aDisplayListBuilder, const StackingContextHelper& aSc,
     wr::DisplayListBuilder& aBuilder, wr::IpcResourceUpdateQueue& aResources) {
   if (!aList->GetBottom()) {
     return;
   }
 
@@ -1353,17 +1361,17 @@ void WebRenderCommandBuilder::DoGrouping
     }
 
     if (group.mResidualOffset != residualOffset) {
       GP(" Residual Offset %f %f -> %f %f\n", group.mResidualOffset.x,
          group.mResidualOffset.y, residualOffset.x, residualOffset.y);
     }
 
     group.ClearItems();
-    group.ClearImageKey(mManager);
+    group.ClearImageKey(mManager->GetRenderRootStateManager());
   }
 
   ScrollableLayerGuid::ViewID scrollId = ScrollableLayerGuid::NULL_SCROLL_ID;
   if (const ActiveScrolledRoot* asr = aWrappingItem->GetActiveScrolledRoot()) {
     scrollId = asr->GetViewId();
   }
 
   g.mAppUnitsPerDevPixel = appUnitsPerDevPixel;
@@ -1611,18 +1619,19 @@ void WebRenderCommandBuilder::CreateWebR
         nsFrame::PrintDisplayItem(aDisplayListBuilder, item, ss,
                                   static_cast<uint32_t>(mDumpIndent));
         printf_stderr("%s", ss.str().c_str());
       }
 
       // Note: this call to CreateWebRenderCommands can recurse back into
       // this function if the |item| is a wrapper for a sublist.
       item->SetPaintRect(item->GetBuildingRect());
+      RenderRootStateManager* manager = mManager->GetRenderRootStateManager();
       bool createdWRCommands = item->CreateWebRenderCommands(
-          aBuilder, aResources, aSc, mManager, aDisplayListBuilder);
+          aBuilder, aResources, aSc, manager, aDisplayListBuilder);
       if (!createdWRCommands) {
         PushItemAsImage(item, aBuilder, aResources, aSc, aDisplayListBuilder);
       }
 
       if (dumpEnabled) {
         mBuilderDumpIndex =
             aBuilder.Dump(mDumpIndent + 1, Some(mBuilderDumpIndex), Nothing());
       }
@@ -2095,18 +2104,18 @@ WebRenderCommandBuilder::GenerateFallbac
       if (!fallbackData->mBasicLayerManager) {
         fallbackData->mBasicLayerManager =
             new BasicLayerManager(BasicLayerManager::BLM_INACTIVE);
       }
       bool isInvalidated = PaintItemByDrawTarget(
           aItem, dt, offset, aDisplayListBuilder,
           fallbackData->mBasicLayerManager, scale, highlight);
       recorder->FlushItem(IntRect({0, 0}, dtSize.ToUnknownSize()));
-      TakeExternalSurfaces(recorder, fallbackData->mExternalSurfaces, mManager,
-                           aResources);
+      TakeExternalSurfaces(recorder, fallbackData->mExternalSurfaces,
+                           mManager->GetRenderRootStateManager(), aResources);
       recorder->Finish();
 
       if (isInvalidated) {
         Range<uint8_t> bytes((uint8_t*)recorder->mOutputStream.mData,
                              recorder->mOutputStream.mLength);
         wr::BlobImageKey key =
             wr::BlobImageKey{mManager->WrBridge()->GetNextImageKey()};
         wr::ImageDescriptor descriptor(dtSize.ToUnknownSize(), 0,
@@ -2180,30 +2189,30 @@ WebRenderCommandBuilder::GenerateFallbac
 
   MOZ_ASSERT(fallbackData->GetImageKey());
 
   return fallbackData.forget();
 }
 
 class WebRenderMaskData : public WebRenderUserData {
  public:
-  explicit WebRenderMaskData(WebRenderLayerManager* aWRManager,
+  explicit WebRenderMaskData(RenderRootStateManager* aManager,
                              nsDisplayItem* aItem)
-      : WebRenderUserData(aWRManager, aItem),
+      : WebRenderUserData(aManager, aItem),
         mMaskStyle(nsStyleImageLayers::LayerType::Mask) {
     MOZ_COUNT_CTOR(WebRenderMaskData);
   }
   virtual ~WebRenderMaskData() {
     MOZ_COUNT_DTOR(WebRenderMaskData);
     ClearImageKey();
   }
 
   void ClearImageKey() {
     if (mBlobKey) {
-      mWRManager->AddBlobImageKeyForDiscard(mBlobKey.value());
+      mManager->AddBlobImageKeyForDiscard(mBlobKey.value());
     }
     mBlobKey.reset();
   }
 
   virtual UserDataType GetType() override { return UserDataType::eMask; }
   static UserDataType Type() { return UserDataType::eMask; }
 
   Maybe<wr::BlobImageKey> mBlobKey;
@@ -2294,17 +2303,18 @@ Maybe<wr::WrImageMask> WebRenderCommandB
     bool maskPainted = false;
     bool paintFinished =
         aMaskItem->PaintMask(aDisplayListBuilder, context, &maskPainted);
     if (!maskPainted) {
       return Nothing();
     }
 
     recorder->FlushItem(IntRect(0, 0, size.width, size.height));
-    TakeExternalSurfaces(recorder, maskData->mExternalSurfaces, mManager,
+    TakeExternalSurfaces(recorder, maskData->mExternalSurfaces,
+                         mManager->GetRenderRootStateManager(),
                          aResources);
     recorder->Finish();
 
     Range<uint8_t> bytes((uint8_t*)recorder->mOutputStream.mData,
                          recorder->mOutputStream.mLength);
     wr::BlobImageKey key =
         wr::BlobImageKey{mManager->WrBridge()->GetNextImageKey()};
     wr::ImageDescriptor descriptor(size, 0, dt->GetFormat(),
@@ -2388,23 +2398,23 @@ void WebRenderCommandBuilder::RemoveUnus
 void WebRenderCommandBuilder::ClearCachedResources() {
   RemoveUnusedAndResetWebRenderUserData();
   // UserDatas should only be in the used state during a call to
   // WebRenderCommandBuilder::BuildWebRenderCommands The should always be false
   // upon return from BuildWebRenderCommands().
   MOZ_RELEASE_ASSERT(mWebRenderUserDatas.Count() == 0);
 }
 
-WebRenderGroupData::WebRenderGroupData(WebRenderLayerManager* aWRManager,
-                                       nsDisplayItem* aItem)
-    : WebRenderUserData(aWRManager, aItem) {
+WebRenderGroupData::WebRenderGroupData(
+    RenderRootStateManager* aRenderRootStateManager, nsDisplayItem* aItem)
+    : WebRenderUserData(aRenderRootStateManager, aItem) {
   MOZ_COUNT_CTOR(WebRenderGroupData);
 }
 
 WebRenderGroupData::~WebRenderGroupData() {
   MOZ_COUNT_DTOR(WebRenderGroupData);
   GP("Group data destruct\n");
-  mSubGroup.ClearImageKey(mWRManager, true);
-  mFollowingGroup.ClearImageKey(mWRManager, true);
+  mSubGroup.ClearImageKey(mManager, true);
+  mFollowingGroup.ClearImageKey(mManager, true);
 }
 
 }  // namespace layers
 }  // namespace mozilla
--- a/gfx/layers/wr/WebRenderCommandBuilder.h
+++ b/gfx/layers/wr/WebRenderCommandBuilder.h
@@ -142,17 +142,17 @@ class WebRenderCommandBuilder {
     RefPtr<WebRenderUserData>& data = userDataTable->GetOrInsert(
         WebRenderUserDataKey(aItem->GetPerFrameKey(), T::Type()));
     if (!data) {
       // To recreate a new user data, we should remove the data from the table
       // first.
       if (data) {
         data->RemoveFromTable();
       }
-      data = new T(mManager, aItem);
+      data = new T(GetRenderRootStateManager(), aItem);
       mWebRenderUserDatas.PutEntry(data);
       if (aOutIsRecycled) {
         *aOutIsRecycled = false;
       }
     }
 
     MOZ_ASSERT(data);
     MOZ_ASSERT(data->GetType() == T::Type());
@@ -166,16 +166,18 @@ class WebRenderCommandBuilder {
     }
     RefPtr<T> res = static_cast<T*>(data.get());
     return res.forget();
   }
 
   WebRenderLayerManager* mManager;
 
  private:
+  RenderRootStateManager* GetRenderRootStateManager();
+
   ClipManager mClipManager;
 
   // We use this as a temporary data structure while building the mScrollData
   // inside a layers-free transaction.
   std::vector<WebRenderLayerScrollData> mLayerScrollData;
   // We use this as a temporary data structure to track the current display
   // item's ASR as we recurse in CreateWebRenderCommandsFromDisplayList. We
   // need this so that WebRenderLayerScrollData items that deeper in the
--- a/gfx/layers/wr/WebRenderLayerManager.cpp
+++ b/gfx/layers/wr/WebRenderLayerManager.cpp
@@ -35,17 +35,18 @@ WebRenderLayerManager::WebRenderLayerMan
     : mWidget(aWidget),
       mLatestTransactionId{0},
       mWindowOverlayChanged(false),
       mNeedsComposite(false),
       mIsFirstPaint(false),
       mTarget(nullptr),
       mPaintSequenceNumber(0),
       mWebRenderCommandBuilder(this),
-      mLastDisplayListSize(0) {
+      mLastDisplayListSize(0),
+      mStateManager(this) {
   MOZ_COUNT_CTOR(WebRenderLayerManager);
 }
 
 KnowsCompositor* WebRenderLayerManager::AsKnowsCompositor() { return mWrChild; }
 
 bool WebRenderLayerManager::Initialize(
     PCompositorBridgeChild* aCBChild, wr::PipelineId aLayersId,
     TextureFactoryIdentifier* aTextureFactoryIdentifier) {
@@ -88,32 +89,22 @@ void WebRenderLayerManager::DoDestroy(bo
   MOZ_ASSERT(NS_IsMainThread());
 
   if (IsDestroyed()) {
     return;
   }
 
   LayerManager::Destroy();
 
+  mStateManager.Destroy();
+
   if (WrBridge()) {
-    // Just clear ImageKeys, they are deleted during WebRenderAPI destruction.
-    DiscardLocalImages();
-    // CompositorAnimations are cleared by WebRenderBridgeParent.
-    mDiscardedCompositorAnimationsIds.Clear();
     WrBridge()->Destroy(aIsSync);
   }
 
-  // Clear this before calling RemoveUnusedAndResetWebRenderUserData(),
-  // otherwise that function might destroy some WebRenderAnimationData instances
-  // which will put stuff back into mDiscardedCompositorAnimationsIds. If
-  // mActiveCompositorAnimationIds is empty that won't happen.
-  mActiveCompositorAnimationIds.clear();
-
-  ClearAsyncAnimations();
-
   mWebRenderCommandBuilder.Destroy();
 
   if (mTransactionIdAllocator) {
     // Make sure to notify the refresh driver just in case it's waiting on a
     // pending transaction. Do this at the top of the event loop so we don't
     // cause a paint to occur during compositor shutdown.
     RefPtr<TransactionIdAllocator> allocator = mTransactionIdAllocator;
     TransactionId id = mLatestTransactionId;
@@ -225,19 +216,20 @@ bool WebRenderLayerManager::EndEmptyTran
   // device-reset status.
   if (!gfxPlatform::GetPlatform()->DidRenderingDeviceReset()) {
     if (WrBridge()->GetSyncObject() &&
         WrBridge()->GetSyncObject()->IsSyncObjectValid()) {
       WrBridge()->GetSyncObject()->Synchronize();
     }
   }
 
+  Maybe<wr::IpcResourceUpdateQueue> nothing;
   WrBridge()->EndEmptyTransaction(mFocusTarget, mPendingScrollUpdates,
-                                  mAsyncResourceUpdates, mPaintSequenceNumber,
-                                  mLatestTransactionId,
+                                  mStateManager.mAsyncResourceUpdates,
+                                  mPaintSequenceNumber, mLatestTransactionId,
                                   mTransactionIdAllocator->GetVsyncId(),
                                   mTransactionIdAllocator->GetVsyncStart(),
                                   refreshStart, mTransactionStart, mURL);
   ClearPendingScrollInfoUpdate();
 
   mTransactionStart = TimeStamp();
 
   MakeSnapshotIfRequired(size);
@@ -293,17 +285,17 @@ void WebRenderLayerManager::EndTransacti
     aBackground->AddWebRenderCommands(builder);
     if (dumpEnabled) {
       printf_stderr("(no display list; background only)\n");
       builderDumpIndex =
           builder.Dump(/*indent*/ 1, Some(builderDumpIndex), Nothing());
     }
   }
 
-  DiscardCompositorAnimations();
+  mStateManager.DiscardCompositorAnimations();
 
   mWidget->AddWindowOverlayWebRenderCommands(WrBridge(), builder,
                                              resourceUpdates);
   mWindowOverlayChanged = false;
   if (dumpEnabled) {
     printf_stderr("(window overlay)\n");
     Unused << builder.Dump(/*indent*/ 1, Some(builderDumpIndex), Nothing());
   }
@@ -328,29 +320,30 @@ void WebRenderLayerManager::EndTransacti
 
   // Get the time of when the refresh driver start its tick (if available),
   // otherwise use the time of when LayerManager::BeginTransaction was called.
   TimeStamp refreshStart = mTransactionIdAllocator->GetTransactionStart();
   if (!refreshStart) {
     refreshStart = mTransactionStart;
   }
 
-  if (mAsyncResourceUpdates) {
+  if (mStateManager.mAsyncResourceUpdates) {
     if (resourceUpdates.IsEmpty()) {
-      resourceUpdates = std::move(mAsyncResourceUpdates.ref());
+      resourceUpdates = std::move(mStateManager.mAsyncResourceUpdates.ref());
     } else {
       // If we can't just swap the queue, we need to take the slow path and
       // send the update as a separate message. We don't need to schedule a
       // composite however because that will happen with EndTransaction.
-      WrBridge()->UpdateResources(mAsyncResourceUpdates.ref());
+      WrBridge()->UpdateResources(mStateManager.mAsyncResourceUpdates.ref());
     }
-    mAsyncResourceUpdates.reset();
+    mStateManager.mAsyncResourceUpdates.reset();
   }
 
-  DiscardImagesInTransaction(resourceUpdates);
+  mStateManager.DiscardImagesInTransaction(resourceUpdates);
+
   WrBridge()->RemoveExpiredFontKeys(resourceUpdates);
 
   // Skip the synchronization for buffer since we also skip the painting during
   // device-reset status.
   if (!gfxPlatform::GetPlatform()->DidRenderingDeviceReset()) {
     if (WrBridge()->GetSyncObject() &&
         WrBridge()->GetSyncObject()->IsSyncObjectValid()) {
       WrBridge()->GetSyncObject()->Synchronize();
@@ -438,73 +431,24 @@ void WebRenderLayerManager::MakeSnapshot
       Matrix::Scaling(1.0, -1.0).PostTranslate(0.0, aSize.height));
   DrawTarget* dt = mTarget->GetDrawTarget();
   MOZ_RELEASE_ASSERT(dt);
   dt->FillRect(dst, pattern);
 
   mTarget = nullptr;
 }
 
-void WebRenderLayerManager::AddImageKeyForDiscard(wr::ImageKey key) {
-  mImageKeysToDelete.AppendElement(key);
-}
-
-void WebRenderLayerManager::AddBlobImageKeyForDiscard(wr::BlobImageKey key) {
-  mBlobImageKeysToDelete.AppendElement(key);
-}
-
-void WebRenderLayerManager::DiscardImagesInTransaction(
-    wr::IpcResourceUpdateQueue& aResources) {
-  for (const auto& key : mImageKeysToDelete) {
-    aResources.DeleteImage(key);
-  }
-  for (const auto& key : mBlobImageKeysToDelete) {
-    aResources.DeleteBlobImage(key);
-  }
-  mImageKeysToDelete.Clear();
-  mBlobImageKeysToDelete.Clear();
-}
-
 void WebRenderLayerManager::DiscardImages() {
   wr::IpcResourceUpdateQueue resources(WrBridge());
-  DiscardImagesInTransaction(resources);
+  mStateManager.DiscardImagesInTransaction(resources);
   WrBridge()->UpdateResources(resources);
 }
 
-void WebRenderLayerManager::AddActiveCompositorAnimationId(uint64_t aId) {
-  // In layers-free mode we track the active compositor animation ids on the
-  // client side so that we don't try to discard the same animation id multiple
-  // times. We could just ignore the multiple-discard on the parent side, but
-  // checking on the content side reduces IPC traffic.
-  mActiveCompositorAnimationIds.insert(aId);
-}
-
-void WebRenderLayerManager::AddCompositorAnimationsIdForDiscard(uint64_t aId) {
-  if (mActiveCompositorAnimationIds.erase(aId)) {
-    // For layers-free ensure we don't try to discard an animation id that
-    // wasn't active. We also remove it from mActiveCompositorAnimationIds so we
-    // don't discard it again unless it gets re-activated.
-    mDiscardedCompositorAnimationsIds.AppendElement(aId);
-  }
-}
-
-void WebRenderLayerManager::DiscardCompositorAnimations() {
-  if (WrBridge()->IPCOpen() && !mDiscardedCompositorAnimationsIds.IsEmpty()) {
-    WrBridge()->SendDeleteCompositorAnimations(
-        mDiscardedCompositorAnimationsIds);
-  }
-  mDiscardedCompositorAnimationsIds.Clear();
-}
-
 void WebRenderLayerManager::DiscardLocalImages() {
-  // Removes images but doesn't tell the parent side about them
-  // This is useful in empty / failed transactions where we created
-  // image keys but didn't tell the parent about them yet.
-  mImageKeysToDelete.Clear();
-  mBlobImageKeysToDelete.Clear();
+  mStateManager.DiscardLocalImages();
 }
 
 void WebRenderLayerManager::SetLayersObserverEpoch(LayersObserverEpoch aEpoch) {
   if (WrBridge()->IPCOpen()) {
     WrBridge()->SendSetLayersObserverEpoch(aEpoch);
   }
 }
 
@@ -542,21 +486,17 @@ void WebRenderLayerManager::DidComposite
     mDidCompositeObservers[i]->DidComposite();
   }
 }
 
 void WebRenderLayerManager::ClearCachedResources(Layer* aSubtree) {
   WrBridge()->BeginClearCachedResources();
   mWebRenderCommandBuilder.ClearCachedResources();
   DiscardImages();
-  // Clear all active compositor animation ids.
-  // When ClearCachedResources is called, all animations are removed
-  // by WebRenderBridgeParent::RecvClearCachedResources().
-  mActiveCompositorAnimationIds.clear();
-  mDiscardedCompositorAnimationsIds.Clear();
+  mStateManager.ClearCachedResources();
   WrBridge()->EndClearCachedResources();
 }
 
 void WebRenderLayerManager::WrUpdated() {
   ClearAsyncAnimations();
   mWebRenderCommandBuilder.ClearCachedResources();
   DiscardLocalImages();
 
@@ -677,75 +617,19 @@ WebRenderLayerManager::CreatePersistentB
                                                AsKnowsCompositor());
     if (provider) {
       return provider.forget();
     }
   }
   return LayerManager::CreatePersistentBufferProvider(aSize, aFormat);
 }
 
-wr::IpcResourceUpdateQueue& WebRenderLayerManager::AsyncResourceUpdates() {
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!mAsyncResourceUpdates) {
-    mAsyncResourceUpdates.emplace(WrBridge());
-
-    RefPtr<Runnable> task = NewRunnableMethod(
-        "WebRenderLayerManager::FlushAsyncResourceUpdates", this,
-        &WebRenderLayerManager::FlushAsyncResourceUpdates);
-    NS_DispatchToMainThread(task.forget());
-  }
-
-  return mAsyncResourceUpdates.ref();
-}
-
-void WebRenderLayerManager::FlushAsyncResourceUpdates() {
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!mAsyncResourceUpdates) {
-    return;
-  }
-
-  if (!IsDestroyed() && WrBridge()) {
-    WrBridge()->UpdateResources(mAsyncResourceUpdates.ref());
-  }
-
-  mAsyncResourceUpdates.reset();
-}
-
-void WebRenderLayerManager::RegisterAsyncAnimation(
-    const wr::ImageKey& aKey, SharedSurfacesAnimation* aAnimation) {
-  mAsyncAnimations.insert(std::make_pair(wr::AsUint64(aKey), aAnimation));
-}
-
-void WebRenderLayerManager::DeregisterAsyncAnimation(const wr::ImageKey& aKey) {
-  mAsyncAnimations.erase(wr::AsUint64(aKey));
-}
-
 void WebRenderLayerManager::ClearAsyncAnimations() {
-  for (const auto& i : mAsyncAnimations) {
-    i.second->Invalidate(this);
-  }
-  mAsyncAnimations.clear();
+  mStateManager.ClearAsyncAnimations();
 }
 
 void WebRenderLayerManager::WrReleasedImages(
     const nsTArray<wr::ExternalImageKeyPair>& aPairs) {
-  // A SharedSurfaceAnimation object's lifetime is tied to its owning
-  // ImageContainer. When the ImageContainer is released,
-  // SharedSurfaceAnimation::Destroy is called which should ensure it is removed
-  // from the layer manager. Whenever the namespace for the
-  // WebRenderLayerManager itself is invalidated (e.g. we changed windows, or
-  // were destroyed ourselves), we callback into the SharedSurfaceAnimation
-  // object to remove its image key for us and any bound surfaces. If, for any
-  // reason, we somehow missed an WrReleasedImages call before the animation
-  // was bound to the layer manager, it will free those associated surfaces on
-  // the next ReleasePreviousFrame call.
-  for (const auto& pair : aPairs) {
-    auto i = mAsyncAnimations.find(wr::AsUint64(pair.key));
-    if (i != mAsyncAnimations.end()) {
-      i->second->ReleasePreviousFrame(this, pair.id);
-    }
-  }
+  mStateManager.WrReleasedImages(aPairs);
 }
 
 }  // namespace layers
 }  // namespace mozilla
--- a/gfx/layers/wr/WebRenderLayerManager.h
+++ b/gfx/layers/wr/WebRenderLayerManager.h
@@ -13,16 +13,17 @@
 
 #include "gfxPrefs.h"
 #include "Layers.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/MozPromise.h"
 #include "mozilla/layers/APZTestData.h"
 #include "mozilla/layers/FocusTarget.h"
 #include "mozilla/layers/IpcResourceUpdateQueue.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/layers/SharedSurfacesChild.h"
 #include "mozilla/layers/StackingContextHelper.h"
 #include "mozilla/layers/TransactionIdAllocator.h"
 #include "mozilla/layers/WebRenderCommandBuilder.h"
 #include "mozilla/layers/WebRenderScrollData.h"
 #include "mozilla/layers/WebRenderUserData.h"
 #include "mozilla/webrender/WebRenderAPI.h"
 #include "mozilla/webrender/WebRenderTypes.h"
@@ -143,38 +144,22 @@ class WebRenderLayerManager final : publ
   virtual already_AddRefed<PersistentBufferProvider>
   CreatePersistentBufferProvider(const gfx::IntSize& aSize,
                                  gfx::SurfaceFormat aFormat) override;
 
   bool AsyncPanZoomEnabled() const override;
 
   // adds an imagekey to a list of keys that will be discarded on the next
   // transaction or destruction
-  void AddImageKeyForDiscard(wr::ImageKey);
-  void AddBlobImageKeyForDiscard(wr::BlobImageKey);
   void DiscardImages();
-  void DiscardImagesInTransaction(wr::IpcResourceUpdateQueue& aResourceUpdates);
   void DiscardLocalImages();
 
-  wr::IpcResourceUpdateQueue& AsyncResourceUpdates();
-  void FlushAsyncResourceUpdates();
-
-  void RegisterAsyncAnimation(const wr::ImageKey& aKey,
-                              SharedSurfacesAnimation* aAnimation);
-  void DeregisterAsyncAnimation(const wr::ImageKey& aKey);
   void ClearAsyncAnimations();
   void WrReleasedImages(const nsTArray<wr::ExternalImageKeyPair>& aPairs);
 
-  // Methods to manage the compositor animation ids. Active animations are still
-  // going, and when they end we discard them and remove them from the active
-  // list.
-  void AddActiveCompositorAnimationId(uint64_t aId);
-  void AddCompositorAnimationsIdForDiscard(uint64_t aId);
-  void DiscardCompositorAnimations();
-
   WebRenderBridgeChild* WrBridge() const { return mWrChild; }
 
   // See equivalent function in ClientLayerManager
   void LogTestDataForCurrentPaint(ScrollableLayerGuid::ViewID aScrollId,
                                   const std::string& aKey,
                                   const std::string& aValue) {
     MOZ_ASSERT(gfxPrefs::APZTestLoggingEnabled(), "don't call me");
     mApzTestData.LogTestDataForPaint(mPaintSequenceNumber, aScrollId, aKey,
@@ -194,34 +179,27 @@ class WebRenderLayerManager final : publ
   nsIWidget* GetWidget() { return mWidget; }
 
   dom::TabGroup* GetTabGroup();
 
   uint32_t StartFrameTimeRecording(int32_t aBufferSize) override;
   void StopFrameTimeRecording(uint32_t aStartIndex,
                               nsTArray<float>& aFrameIntervals) override;
 
+  RenderRootStateManager* GetRenderRootStateManager() { return &mStateManager; }
+
  private:
   /**
    * Take a snapshot of the parent context, and copy
    * it into mTarget.
    */
   void MakeSnapshotIfRequired(LayoutDeviceIntSize aSize);
 
  private:
   nsIWidget* MOZ_NON_OWNING_REF mWidget;
-  nsTArray<wr::ImageKey> mImageKeysToDelete;
-  nsTArray<wr::BlobImageKey> mBlobImageKeysToDelete;
-
-  // Set of compositor animation ids for which there are active animations (as
-  // of the last transaction) on the compositor side.
-  std::unordered_set<uint64_t> mActiveCompositorAnimationIds;
-  // Compositor animation ids for animations that are done now and that we want
-  // the compositor to discard information for.
-  nsTArray<uint64_t> mDiscardedCompositorAnimationsIds;
 
   RefPtr<WebRenderBridgeChild> mWrChild;
 
   RefPtr<TransactionIdAllocator> mTransactionIdAllocator;
   TransactionId mLatestTransactionId;
 
   nsTArray<DidCompositeObserver*> mDidCompositeObservers;
 
@@ -249,17 +227,15 @@ class WebRenderLayerManager final : publ
   APZTestData mApzTestData;
 
   TimeStamp mTransactionStart;
   nsCString mURL;
   WebRenderCommandBuilder mWebRenderCommandBuilder;
 
   size_t mLastDisplayListSize;
 
-  Maybe<wr::IpcResourceUpdateQueue> mAsyncResourceUpdates;
-  std::unordered_map<uint64_t, RefPtr<SharedSurfacesAnimation>>
-      mAsyncAnimations;
+  RenderRootStateManager mStateManager;
 };
 
 }  // namespace layers
 }  // namespace mozilla
 
 #endif /* GFX_WEBRENDERLAYERMANAGER_H */
--- a/gfx/layers/wr/WebRenderUserData.cpp
+++ b/gfx/layers/wr/WebRenderUserData.cpp
@@ -4,17 +4,17 @@
  * 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 "WebRenderUserData.h"
 
 #include "mozilla/layers/CompositorBridgeChild.h"
 #include "mozilla/layers/ImageClient.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
-#include "mozilla/layers/WebRenderLayerManager.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/layers/WebRenderMessages.h"
 #include "mozilla/layers/IpcResourceUpdateQueue.h"
 #include "mozilla/layers/SharedSurfacesChild.h"
 #include "nsDisplayListInvalidation.h"
 #include "nsIFrame.h"
 #include "WebRenderCanvasRenderer.h"
 
 namespace mozilla {
@@ -60,54 +60,54 @@ void WebRenderBackgroundData::AddWebRend
   if (image && image->IsAsyncAnimatedImage()) {
     return true;
   }
 
   aFrame->SchedulePaint();
   return false;
 }
 
-WebRenderUserData::WebRenderUserData(WebRenderLayerManager* aWRManager,
+WebRenderUserData::WebRenderUserData(RenderRootStateManager* aManager,
                                      nsDisplayItem* aItem)
-    : mWRManager(aWRManager),
+    : mManager(aManager),
       mFrame(aItem->Frame()),
       mDisplayItemKey(aItem->GetPerFrameKey()),
-      mTable(aWRManager->GetWebRenderUserDataTable()),
+      mTable(aManager->GetWebRenderUserDataTable()),
       mUsed(false) {}
 
 WebRenderUserData::~WebRenderUserData() {}
 
 void WebRenderUserData::RemoveFromTable() { mTable->RemoveEntry(this); }
 
 WebRenderBridgeChild* WebRenderUserData::WrBridge() const {
-  return mWRManager->WrBridge();
+  return mManager->WrBridge();
 }
 
-WebRenderImageData::WebRenderImageData(WebRenderLayerManager* aWRManager,
+WebRenderImageData::WebRenderImageData(RenderRootStateManager* aManager,
                                        nsDisplayItem* aItem)
-    : WebRenderUserData(aWRManager, aItem), mOwnsKey(false) {}
+    : WebRenderUserData(aManager, aItem), mOwnsKey(false) {}
 
 WebRenderImageData::~WebRenderImageData() {
   ClearImageKey();
 
   if (mPipelineId) {
-    WrBridge()->RemovePipelineIdForCompositable(mPipelineId.ref());
+    mManager->RemovePipelineIdForCompositable(mPipelineId.ref());
   }
 }
 
 bool WebRenderImageData::IsAsyncAnimatedImage() const {
   return mContainer && mContainer->GetSharedSurfacesAnimation();
 }
 
 void WebRenderImageData::ClearImageKey() {
   if (mKey) {
     // If we don't own the key, then the owner is responsible for discarding the
     // key when appropriate.
     if (mOwnsKey) {
-      mWRManager->AddImageKeyForDiscard(mKey.value());
+      mManager->AddImageKeyForDiscard(mKey.value());
       if (mTextureOfImage) {
         WrBridge()->ReleaseTextureOfImage(mKey.value());
         mTextureOfImage = nullptr;
       }
     }
     mKey.reset();
   }
   mOwnsKey = false;
@@ -121,17 +121,17 @@ Maybe<wr::ImageKey> WebRenderImageData::
 
   if (mContainer != aContainer) {
     mContainer = aContainer;
   }
 
   wr::WrImageKey key;
   if (!aFallback) {
     nsresult rv =
-        SharedSurfacesChild::Share(aContainer, mWRManager, aResources, key);
+        SharedSurfacesChild::Share(aContainer, mManager, aResources, key);
     if (NS_SUCCEEDED(rv)) {
       // Ensure that any previously owned keys are released before replacing. We
       // don't own this key, the surface itself owns it, so that it can be
       // shared across multiple elements.
       ClearImageKey();
       mKey = Some(key);
       return mKey;
     }
@@ -249,19 +249,19 @@ void WebRenderImageData::CreateImageClie
     if (!mImageClient) {
       return;
     }
 
     mImageClient->Connect();
   }
 }
 
-WebRenderFallbackData::WebRenderFallbackData(WebRenderLayerManager* aWRManager,
+WebRenderFallbackData::WebRenderFallbackData(RenderRootStateManager* aManager,
                                              nsDisplayItem* aItem)
-    : WebRenderImageData(aWRManager, aItem), mInvalid(false) {}
+    : WebRenderImageData(aManager, aItem), mInvalid(false) {}
 
 WebRenderFallbackData::~WebRenderFallbackData() { ClearImageKey(); }
 
 nsDisplayItemGeometry* WebRenderFallbackData::GetGeometry() {
   return mGeometry.get();
 }
 
 void WebRenderFallbackData::SetGeometry(
@@ -280,56 +280,56 @@ Maybe<wr::ImageKey> WebRenderFallbackDat
     return Some(wr::AsImageKey(mBlobKey.value()));
   }
 
   return mKey;
 }
 
 void WebRenderFallbackData::ClearImageKey() {
   if (mBlobKey && mOwnsKey) {
-    mWRManager->AddBlobImageKeyForDiscard(mBlobKey.value());
+    mManager->AddBlobImageKeyForDiscard(mBlobKey.value());
   }
   mBlobKey.reset();
 
   WebRenderImageData::ClearImageKey();
 }
 
-WebRenderAnimationData::WebRenderAnimationData(
-    WebRenderLayerManager* aWRManager, nsDisplayItem* aItem)
-    : WebRenderUserData(aWRManager, aItem) {}
+WebRenderAnimationData::WebRenderAnimationData(RenderRootStateManager* aManager,
+                                               nsDisplayItem* aItem)
+    : WebRenderUserData(aManager, aItem) {}
 
 WebRenderAnimationData::~WebRenderAnimationData() {
   // It may be the case that nsDisplayItem that created this WebRenderUserData
   // gets destroyed without getting a chance to discard the compositor animation
   // id, so we should do it as part of cleanup here.
   uint64_t animationId = mAnimationInfo.GetCompositorAnimationsId();
   // animationId might be 0 if mAnimationInfo never held any active animations.
   if (animationId) {
-    mWRManager->AddCompositorAnimationsIdForDiscard(animationId);
+    mManager->AddCompositorAnimationsIdForDiscard(animationId);
   }
 }
 
-WebRenderCanvasData::WebRenderCanvasData(WebRenderLayerManager* aWRManager,
+WebRenderCanvasData::WebRenderCanvasData(RenderRootStateManager* aManager,
                                          nsDisplayItem* aItem)
-    : WebRenderUserData(aWRManager, aItem) {}
+    : WebRenderUserData(aManager, aItem) {}
 
 WebRenderCanvasData::~WebRenderCanvasData() {
   if (mCanvasRenderer) {
     mCanvasRenderer->ClearCachedResources();
   }
 }
 
 void WebRenderCanvasData::ClearCanvasRenderer() { mCanvasRenderer = nullptr; }
 
 WebRenderCanvasRendererAsync* WebRenderCanvasData::GetCanvasRenderer() {
   return mCanvasRenderer.get();
 }
 
 WebRenderCanvasRendererAsync* WebRenderCanvasData::CreateCanvasRenderer() {
-  mCanvasRenderer = MakeUnique<WebRenderCanvasRendererAsync>(mWRManager);
+  mCanvasRenderer = MakeUnique<WebRenderCanvasRendererAsync>(mManager);
   return mCanvasRenderer.get();
 }
 
 void DestroyWebRenderUserDataTable(WebRenderUserDataTable* aTable) {
   for (auto iter = aTable->Iter(); !iter.Done(); iter.Next()) {
     iter.UserData()->RemoveFromTable();
   }
   delete aTable;
--- a/gfx/layers/wr/WebRenderUserData.h
+++ b/gfx/layers/wr/WebRenderUserData.h
@@ -29,17 +29,17 @@ namespace layers {
 class CanvasLayer;
 class ImageClient;
 class ImageContainer;
 class WebRenderBridgeChild;
 class WebRenderCanvasData;
 class WebRenderCanvasRendererAsync;
 class WebRenderImageData;
 class WebRenderFallbackData;
-class WebRenderLayerManager;
+class RenderRootStateManager;
 class WebRenderGroupData;
 
 class WebRenderBackgroundData {
  public:
   WebRenderBackgroundData(wr::LayoutRect aBounds, wr::ColorF aColor)
       : mBounds(aBounds), mColor(aColor) {}
   void AddWebRenderCommands(wr::DisplayListBuilder& aBuilder);
 
@@ -55,17 +55,17 @@ class WebRenderUserData {
 
   static bool SupportsAsyncUpdate(nsIFrame* aFrame);
 
   static bool ProcessInvalidateForImage(nsIFrame* aFrame,
                                         DisplayItemType aType);
 
   NS_INLINE_DECL_REFCOUNTING(WebRenderUserData)
 
-  WebRenderUserData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem);
+  WebRenderUserData(RenderRootStateManager* aManager, nsDisplayItem* aItem);
 
   virtual WebRenderImageData* AsImageData() { return nullptr; }
   virtual WebRenderFallbackData* AsFallbackData() { return nullptr; }
   virtual WebRenderCanvasData* AsCanvasData() { return nullptr; }
   virtual WebRenderGroupData* AsGroupData() { return nullptr; }
 
   enum class UserDataType {
     eImage,
@@ -84,17 +84,17 @@ class WebRenderUserData {
   void RemoveFromTable();
   virtual nsDisplayItemGeometry* GetGeometry() { return nullptr; }
 
  protected:
   virtual ~WebRenderUserData();
 
   WebRenderBridgeChild* WrBridge() const;
 
-  RefPtr<WebRenderLayerManager> mWRManager;
+  RefPtr<RenderRootStateManager> mManager;
   nsIFrame* mFrame;
   uint32_t mDisplayItemKey;
   WebRenderUserDataRefTable* mTable;
   bool mUsed;
 };
 
 struct WebRenderUserDataKey {
   WebRenderUserDataKey(uint32_t aFrameKey,
@@ -117,17 +117,17 @@ struct WebRenderUserDataKey {
 typedef nsRefPtrHashtable<
     nsGenericHashKey<mozilla::layers::WebRenderUserDataKey>, WebRenderUserData>
     WebRenderUserDataTable;
 
 /// Holds some data used to share TextureClient/ImageClient with the parent
 /// process except if used with blob images (watch your step).
 class WebRenderImageData : public WebRenderUserData {
  public:
-  WebRenderImageData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem);
+  WebRenderImageData(RenderRootStateManager* aManager, nsDisplayItem* aItem);
   virtual ~WebRenderImageData();
 
   virtual WebRenderImageData* AsImageData() override { return this; }
   virtual UserDataType GetType() override { return UserDataType::eImage; }
   static UserDataType Type() { return UserDataType::eImage; }
   virtual Maybe<wr::ImageKey> GetImageKey() { return mKey; }
   void SetImageKey(const wr::ImageKey& aKey);
   already_AddRefed<ImageClient> GetImageClient();
@@ -166,18 +166,17 @@ class WebRenderImageData : public WebRen
 /// side directly into a texture.
 ///
 /// TODO(nical) It would be much better to separate the two use cases into
 /// separate classes and not have the blob image related code inherit from
 /// WebRenderImageData (the current code only works if we carefully use a subset
 /// of the parent code).
 class WebRenderFallbackData : public WebRenderImageData {
  public:
-  WebRenderFallbackData(WebRenderLayerManager* aWRManager,
-                        nsDisplayItem* aItem);
+  WebRenderFallbackData(RenderRootStateManager* aManager, nsDisplayItem* aItem);
   virtual ~WebRenderFallbackData();
 
   virtual WebRenderFallbackData* AsFallbackData() override { return this; }
   virtual UserDataType GetType() override { return UserDataType::eFallback; }
   static UserDataType Type() { return UserDataType::eFallback; }
   nsDisplayItemGeometry* GetGeometry() override;
   void SetGeometry(nsAutoPtr<nsDisplayItemGeometry> aGeometry);
   nsRect GetBounds() { return mBounds; }
@@ -204,31 +203,31 @@ class WebRenderFallbackData : public Web
   nsRect mBounds;
   bool mInvalid;
   gfx::Size mScale;
   std::vector<RefPtr<gfx::ScaledFont>> mFonts;
 };
 
 class WebRenderAnimationData : public WebRenderUserData {
  public:
-  WebRenderAnimationData(WebRenderLayerManager* aWRManager,
+  WebRenderAnimationData(RenderRootStateManager* aManager,
                          nsDisplayItem* aItem);
   virtual ~WebRenderAnimationData();
 
   virtual UserDataType GetType() override { return UserDataType::eAnimation; }
   static UserDataType Type() { return UserDataType::eAnimation; }
   AnimationInfo& GetAnimationInfo() { return mAnimationInfo; }
 
  protected:
   AnimationInfo mAnimationInfo;
 };
 
 class WebRenderCanvasData : public WebRenderUserData {
  public:
-  WebRenderCanvasData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem);
+  WebRenderCanvasData(RenderRootStateManager* aManager, nsDisplayItem* aItem);
   virtual ~WebRenderCanvasData();
 
   virtual WebRenderCanvasData* AsCanvasData() override { return this; }
   virtual UserDataType GetType() override { return UserDataType::eCanvas; }
   static UserDataType Type() { return UserDataType::eCanvas; }
 
   void ClearCanvasRenderer();
   WebRenderCanvasRendererAsync* GetCanvasRenderer();
--- a/gfx/src/nsITheme.h
+++ b/gfx/src/nsITheme.h
@@ -23,17 +23,17 @@ class nsIFrame;
 class nsAtom;
 class nsIWidget;
 
 namespace mozilla {
 class ComputedStyle;
 enum class StyleAppearance : uint8_t;
 namespace layers {
 class StackingContextHelper;
-class WebRenderLayerManager;
+class RenderRootStateManager;
 }  // namespace layers
 namespace wr {
 class DisplayListBuilder;
 class IpcResourceUpdateQueue;
 }  // namespace wr
 }  // namespace mozilla
 
 // IID for the nsITheme interface
@@ -81,17 +81,17 @@ class nsITheme : public nsISupports {
    * @return true if the theme knows how to create WebRender commands for the
    *         given widget type, false if DrawWidgetBackground need sto be called
    *         instead.
    */
   virtual bool CreateWebRenderCommandsForWidget(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const mozilla::layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager, nsIFrame* aFrame,
+      mozilla::layers::RenderRootStateManager* aManager, nsIFrame* aFrame,
       StyleAppearance aWidgetType, const nsRect& aRect) {
     return false;
   }
 
   /**
    * Return the border for the widget, in device pixels.
    */
   virtual MOZ_MUST_USE LayoutDeviceIntMargin
--- a/gfx/thebes/gfxFontMissingGlyphs.cpp
+++ b/gfx/thebes/gfxFontMissingGlyphs.cpp
@@ -218,17 +218,17 @@ static void PurgeWRGlyphAtlas() {
   // from the layer manager.
   for (WRUserData* user : gWRUsers) {
     auto* manager = user->mManager;
     for (size_t i = 0; i < 8; i++) {
       if (gWRGlyphAtlas[i]) {
         uint32_t handle = (uint32_t)(uintptr_t)gWRGlyphAtlas[i]->GetUserData(
             reinterpret_cast<UserDataKey*>(manager));
         if (handle) {
-          manager->AddImageKeyForDiscard(
+          manager->GetRenderRootStateManager()->AddImageKeyForDiscard(
               wr::ImageKey{manager->WrBridge()->GetNamespace(), handle});
         }
       }
     }
   }
   // Remove the layer managers' destroy notifications only after processing
   // so as not to mess up gWRUsers iteration.
   while (!gWRUsers.isEmpty()) {
--- a/gfx/webrender_bindings/WebRenderAPI.cpp
+++ b/gfx/webrender_bindings/WebRenderAPI.cpp
@@ -1073,17 +1073,17 @@ Maybe<layers::ScrollableLayerGuid::ViewI
 DisplayListBuilder::FixedPosScrollTargetTracker::GetScrollTargetForASR(
     const ActiveScrolledRoot* aAsr) {
   return aAsr == mAsr ? Some(mScrollId) : Nothing();
 }
 
 already_AddRefed<gfxContext> DisplayListBuilder::GetTextContext(
     wr::IpcResourceUpdateQueue& aResources,
     const layers::StackingContextHelper& aSc,
-    layers::WebRenderLayerManager* aManager, nsDisplayItem* aItem,
+    layers::RenderRootStateManager* aManager, nsDisplayItem* aItem,
     nsRect& aBounds, const gfx::Point& aDeviceOffset) {
   if (!mCachedTextDT) {
     mCachedTextDT = new layout::TextDrawTarget(*this, aResources, aSc, aManager,
                                                aItem, aBounds);
     mCachedContext = gfxContext::CreateOrNull(mCachedTextDT, aDeviceOffset);
   } else {
     mCachedTextDT->Reinitialize(aResources, aSc, aManager, aItem, aBounds);
     mCachedContext->SetDeviceOffset(aDeviceOffset);
--- a/gfx/webrender_bindings/WebRenderAPI.h
+++ b/gfx/webrender_bindings/WebRenderAPI.h
@@ -30,17 +30,17 @@ struct ActiveScrolledRoot;
 
 namespace widget {
 class CompositorWidget;
 }
 
 namespace layers {
 class CompositorBridgeParent;
 class WebRenderBridgeParent;
-class WebRenderLayerManager;
+class RenderRootStateManager;
 }  // namespace layers
 
 namespace layout {
 class TextDrawTarget;
 }
 
 namespace wr {
 
@@ -499,17 +499,17 @@ class DisplayListBuilder {
   void SetHitTestInfo(const layers::ScrollableLayerGuid::ViewID& aScrollId,
                       gfx::CompositorHitTestInfo aHitInfo);
   // Clears the hit-test info so that subsequent display items will not have it.
   void ClearHitTestInfo();
 
   already_AddRefed<gfxContext> GetTextContext(
       wr::IpcResourceUpdateQueue& aResources,
       const layers::StackingContextHelper& aSc,
-      layers::WebRenderLayerManager* aManager, nsDisplayItem* aItem,
+      layers::RenderRootStateManager* aManager, nsDisplayItem* aItem,
       nsRect& aBounds, const gfx::Point& aDeviceOffset);
 
   // Try to avoid using this when possible.
   wr::WrState* Raw() { return mWrState; }
 
   // A chain of RAII objects, each holding a (ASR, ViewID) tuple of data. The
   // topmost object is pointed to by the mActiveFixedPosTracker pointer in
   // the wr::DisplayListBuilder.
--- a/layout/forms/nsButtonFrameRenderer.cpp
+++ b/layout/forms/nsButtonFrameRenderer.cpp
@@ -14,17 +14,17 @@
 #include "nsDisplayList.h"
 #include "nsITheme.h"
 #include "nsFrame.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/dom/Element.h"
 #include "Layers.h"
 #include "gfxPrefs.h"
 #include "gfxUtils.h"
-#include "mozilla/layers/WebRenderLayerManager.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 
 #define ACTIVE "active"
 #define HOVER "hover"
 #define FOCUS "focus"
 
 using namespace mozilla;
 using namespace mozilla::image;
 using namespace mozilla::layers;
@@ -71,17 +71,17 @@ class nsDisplayButtonBoxShadowOuter : pu
     MOZ_COUNT_DTOR(nsDisplayButtonBoxShadowOuter);
   }
 #endif
 
   virtual bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
   bool CanBuildWebRenderDisplayItems();
 
   virtual void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
   virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
                            bool* aSnap) const override;
   NS_DISPLAY_DECL_NAME("ButtonBoxShadowOuter", TYPE_BUTTON_BOX_SHADOW_OUTER)
@@ -119,17 +119,17 @@ bool nsDisplayButtonBoxShadowOuter::CanB
 
   return true;
 }
 
 bool nsDisplayButtonBoxShadowOuter::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   if (!CanBuildWebRenderDisplayItems()) {
     return false;
   }
   int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
   nsRect shadowRect = nsRect(ToReferenceFrame(), mFrame->GetSize());
   LayoutDeviceRect deviceBox =
       LayoutDeviceRect::FromAppUnits(shadowRect, appUnitsPerDevPixel);
@@ -207,33 +207,33 @@ class nsDisplayButtonBorder final : publ
       nsDisplayListBuilder* aBuilder) override;
   virtual void ComputeInvalidationRegion(
       nsDisplayListBuilder* aBuilder, const nsDisplayItemGeometry* aGeometry,
       nsRegion* aInvalidRegion) const override;
   virtual bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   NS_DISPLAY_DECL_NAME("ButtonBorderBackground", TYPE_BUTTON_BORDER_BACKGROUND)
  private:
   nsButtonFrameRenderer* mBFR;
 };
 
 nsDisplayItemGeometry* nsDisplayButtonBorder::AllocateGeometry(
     nsDisplayListBuilder* aBuilder) {
   return new nsDisplayItemGenericImageGeometry(this, aBuilder);
 }
 
 bool nsDisplayButtonBorder::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   // This is really a combination of paint box shadow inner +
   // paint border.
   nsRect buttonRect = nsRect(ToReferenceFrame(), mFrame->GetSize());
   bool snap;
   nsRegion visible = GetBounds(aDisplayListBuilder, &snap);
   nsDisplayBoxShadowInner::CreateInsetBoxShadowWebRenderCommands(
       aBuilder, aSc, visible, mFrame, buttonRect);
@@ -307,17 +307,17 @@ class nsDisplayButtonForeground final : 
   void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
                                  const nsDisplayItemGeometry* aGeometry,
                                  nsRegion* aInvalidRegion) const override;
   virtual void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
   virtual bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   NS_DISPLAY_DECL_NAME("ButtonForeground", TYPE_BUTTON_FOREGROUND)
  private:
   nsButtonFrameRenderer* mBFR;
 };
 
 nsDisplayItemGeometry* nsDisplayButtonForeground::AllocateGeometry(
     nsDisplayListBuilder* aBuilder) {
@@ -354,17 +354,17 @@ void nsDisplayButtonForeground::Paint(ns
     nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, result);
   }
 }
 
 bool nsDisplayButtonForeground::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   Maybe<nsCSSBorderRenderer> br;
   bool borderIsEmpty = false;
   nsPresContext* presContext = mFrame->PresContext();
   const nsStyleDisplay* disp = mFrame->StyleDisplay();
   if (!mFrame->IsThemed(disp) ||
       !presContext->GetTheme()->ThemeDrawsFocusForWidget(disp->mAppearance)) {
     nsRect r = nsRect(ToReferenceFrame(), mFrame->GetSize());
--- a/layout/forms/nsFieldSetFrame.cpp
+++ b/layout/forms/nsFieldSetFrame.cpp
@@ -103,17 +103,17 @@ class nsDisplayFieldSetBorder final : pu
       nsDisplayListBuilder* aBuilder) override;
   virtual void ComputeInvalidationRegion(
       nsDisplayListBuilder* aBuilder, const nsDisplayItemGeometry* aGeometry,
       nsRegion* aInvalidRegion) const override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
                            bool* aSnap) const override;
   NS_DISPLAY_DECL_NAME("FieldSetBorder", TYPE_FIELDSET_BORDER_BACKGROUND)
 };
 
 void nsDisplayFieldSetBorder::Paint(nsDisplayListBuilder* aBuilder,
                                     gfxContext* aCtx) {
@@ -154,17 +154,17 @@ nsRect nsDisplayFieldSetBorder::GetBound
   *aSnap = false;
   return Frame()->GetVisualOverflowRectRelativeToSelf() + ToReferenceFrame();
 }
 
 bool nsDisplayFieldSetBorder::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   auto frame = static_cast<nsFieldSetFrame*>(mFrame);
   auto offset = ToReferenceFrame();
   nsRect rect;
 
   if (nsIFrame* legend = frame->GetLegend()) {
     rect = frame->VisualBorderRectRelativeToSelf() + offset;
 
--- a/layout/generic/TextDrawTarget.h
+++ b/layout/generic/TextDrawTarget.h
@@ -3,16 +3,17 @@
 /* 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 TextDrawTarget_h
 #define TextDrawTarget_h
 
 #include "mozilla/gfx/2D.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/layers/WebRenderLayerManager.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
 #include "mozilla/webrender/WebRenderAPI.h"
 #include "mozilla/layers/StackingContextHelper.h"
 #include "mozilla/layers/IpcResourceUpdateQueue.h"
 
 namespace mozilla {
 namespace layout {
@@ -47,32 +48,32 @@ using namespace gfx;
 //
 // TextDrawTarget doesn't yet support all features. See mHasUnsupportedFeatures
 // for details.
 class TextDrawTarget : public DrawTarget {
  public:
   explicit TextDrawTarget(wr::DisplayListBuilder& aBuilder,
                           wr::IpcResourceUpdateQueue& aResources,
                           const layers::StackingContextHelper& aSc,
-                          layers::WebRenderLayerManager* aManager,
+                          layers::RenderRootStateManager* aManager,
                           nsDisplayItem* aItem, nsRect& aBounds,
                           bool aCallerDoesSaveRestore = false)
       : mCallerDoesSaveRestore(aCallerDoesSaveRestore), mBuilder(aBuilder) {
     Reinitialize(aResources, aSc, aManager, aItem, aBounds);
   }
 
   // Prevent this from being copied
   TextDrawTarget(const TextDrawTarget& src) = delete;
   TextDrawTarget& operator=(const TextDrawTarget&) = delete;
 
   ~TextDrawTarget() { MOZ_ASSERT(mFinished); }
 
   void Reinitialize(wr::IpcResourceUpdateQueue& aResources,
                     const layers::StackingContextHelper& aSc,
-                    layers::WebRenderLayerManager* aManager,
+                    layers::RenderRootStateManager* aManager,
                     nsDisplayItem* aItem, nsRect& aBounds) {
     mResources = &aResources;
     mSc = &aSc;
     mManager = aManager;
     mHasUnsupportedFeatures = false;
     mHasShadows = false;
 
     SetPermitSubpixelAA(!aItem->IsSubpixelAADisabled());
@@ -312,17 +313,19 @@ class TextDrawTarget : public DrawTarget
     decoration.orientation = aVertical ? wr::LineOrientation::Vertical
                                        : wr::LineOrientation::Horizontal;
     decoration.style = wr::LineStyle::Wavy;
 
     mBuilder.PushLine(ClipRect(), mBackfaceVisible, decoration);
   }
 
   layers::WebRenderBridgeChild* WrBridge() { return mManager->WrBridge(); }
-  layers::WebRenderLayerManager* WrLayerManager() { return mManager; }
+  layers::WebRenderLayerManager* WrLayerManager() {
+    return mManager->LayerManager();
+  }
 
   Maybe<wr::ImageKey> DefineImage(const IntSize& aSize, uint32_t aStride,
                                   SurfaceFormat aFormat, const uint8_t* aData) {
     wr::ImageKey key = mManager->WrBridge()->GetNextImageKey();
     wr::ImageDescriptor desc(aSize, aStride, aFormat);
     Range<uint8_t> bytes(const_cast<uint8_t*>(aData), aStride * aSize.height);
     if (mResources->AddImage(key, desc, bytes)) {
       return Some(key);
@@ -363,17 +366,17 @@ class TextDrawTarget : public DrawTarget
 
   // Whether PopAllShadows needs to be called
   bool mHasShadows = false;
 
   // Things used to push to webrender
   wr::DisplayListBuilder& mBuilder;
   wr::IpcResourceUpdateQueue* mResources;
   const layers::StackingContextHelper* mSc;
-  layers::WebRenderLayerManager* mManager;
+  layers::RenderRootStateManager* mManager;
 
   // Computed facts
   IntSize mSize;
   wr::LayoutRect mBoundsRect;
   AutoTArray<LayoutDeviceRect, 3> mClipStack;
   bool mBackfaceVisible;
 
   wr::FontInstanceFlags mWRGlyphFlags = {0};
--- a/layout/generic/TextOverflow.cpp
+++ b/layout/generic/TextOverflow.cpp
@@ -190,17 +190,18 @@ class nsDisplayTextOverflowMarker final 
   virtual uint32_t GetPerFrameKey() const override {
     return (mIndex << TYPE_BITS) | nsDisplayItem::GetPerFrameKey();
   }
   void PaintTextToContext(gfxContext* aCtx, nsPoint aOffsetFromRect);
 
   virtual bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
-      const StackingContextHelper& aSc, layers::WebRenderLayerManager* aManager,
+      const StackingContextHelper& aSc,
+      layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
   NS_DISPLAY_DECL_NAME("TextOverflow", TYPE_TEXT_OVERFLOW)
  private:
   nsRect mRect;  // in reference frame coordinates
   const nsStyleTextOverflowSide mStyle;
   nscoord mAscent;  // baseline for the marker text in mRect
   uint32_t mIndex;
@@ -261,17 +262,17 @@ void nsDisplayTextOverflowMarker::PaintT
     nsLayoutUtils::DrawString(mFrame, *fm, aCtx, mStyle.mString.get(),
                               mStyle.mString.Length(), pt);
   }
 }
 
 bool nsDisplayTextOverflowMarker::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
-    const StackingContextHelper& aSc, layers::WebRenderLayerManager* aManager,
+    const StackingContextHelper& aSc, layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   bool snap;
   nsRect bounds = GetBounds(aDisplayListBuilder, &snap);
   if (bounds.IsEmpty()) {
     return true;
   }
 
   // Run the rendering algorithm to capture the glyphs and shadows
--- a/layout/generic/nsBulletFrame.cpp
+++ b/layout/generic/nsBulletFrame.cpp
@@ -11,17 +11,17 @@
 #include "gfx2DGlue.h"
 #include "gfxContext.h"
 #include "gfxPrefs.h"
 #include "gfxUtils.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/PathHelpers.h"
 #include "mozilla/layers/LayersMessages.h"
 #include "mozilla/layers/StackingContextHelper.h"
-#include "mozilla/layers/WebRenderLayerManager.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/layers/WebRenderMessages.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/Move.h"
 #include "nsCOMPtr.h"
 #include "nsFontMetrics.h"
 #include "nsGkAtoms.h"
 #include "nsGenericHTMLElement.h"
 #include "nsAttrValueInlines.h"
@@ -211,17 +211,17 @@ class BulletRenderer final {
         mListStyleType(listStyleType) {
     MOZ_ASSERT(IsTextType());
   }
 
   ImgDrawResult CreateWebRenderCommands(
       nsDisplayItem* aItem, wr::DisplayListBuilder& aBuilder,
       wr::IpcResourceUpdateQueue& aResources,
       const layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder);
 
   ImgDrawResult Paint(gfxContext& aRenderingContext, nsPoint aPt,
                       const nsRect& aDirtyRect, uint32_t aFlags,
                       bool aDisableSubpixelAA, nsIFrame* aFrame);
 
   bool IsImageType() const {
     return mListStyleType == NS_STYLE_LIST_STYLE_NONE && mImage;
@@ -251,31 +251,31 @@ class BulletRenderer final {
   bool IsImageContainerAvailable(layers::LayerManager* aManager,
                                  uint32_t aFlags);
 
  private:
   ImgDrawResult CreateWebRenderCommandsForImage(
       nsDisplayItem* aItem, wr::DisplayListBuilder& aBuilder,
       wr::IpcResourceUpdateQueue& aResources,
       const layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder);
 
   bool CreateWebRenderCommandsForPath(
       nsDisplayItem* aItem, wr::DisplayListBuilder& aBuilder,
       wr::IpcResourceUpdateQueue& aResources,
       const layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder);
 
   bool CreateWebRenderCommandsForText(
       nsDisplayItem* aItem, wr::DisplayListBuilder& aBuilder,
       wr::IpcResourceUpdateQueue& aResources,
       const layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder);
 
  private:
   // mImage and mDest are the properties for list-style-image.
   // mImage is the image content and mDest is the image position.
   RefPtr<imgIContainer> mImage;
   nsRect mDest;
 
@@ -308,17 +308,17 @@ class BulletRenderer final {
   // Store the type of list-style-type.
   int32_t mListStyleType;
 };
 
 ImgDrawResult BulletRenderer::CreateWebRenderCommands(
     nsDisplayItem* aItem, wr::DisplayListBuilder& aBuilder,
     wr::IpcResourceUpdateQueue& aResources,
     const layers::StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   if (IsImageType()) {
     return CreateWebRenderCommandsForImage(aItem, aBuilder, aResources, aSc,
                                            aManager, aDisplayListBuilder);
   }
 
   bool success;
   if (IsPathType()) {
@@ -410,17 +410,17 @@ bool BulletRenderer::IsImageContainerAva
 
   return mImage->IsImageContainerAvailable(aManager, aFlags);
 }
 
 ImgDrawResult BulletRenderer::CreateWebRenderCommandsForImage(
     nsDisplayItem* aItem, wr::DisplayListBuilder& aBuilder,
     wr::IpcResourceUpdateQueue& aResources,
     const layers::StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   MOZ_RELEASE_ASSERT(IsImageType());
   MOZ_RELEASE_ASSERT(mImage);
 
   uint32_t flags = imgIContainer::FLAG_ASYNC_NOTIFY;
   if (aDisplayListBuilder->IsPaintingToWindow()) {
     flags |= imgIContainer::FLAG_HIGH_QUALITY_SCALING;
   }
@@ -434,17 +434,18 @@ ImgDrawResult BulletRenderer::CreateWebR
       LayoutDeviceRect::FromAppUnits(mDest, appUnitsPerDevPixel);
   Maybe<SVGImageContext> svgContext;
   gfx::IntSize decodeSize =
       nsLayoutUtils::ComputeImageContainerDrawingParameters(
           mImage, aItem->Frame(), destRect, aSc, flags, svgContext);
 
   RefPtr<layers::ImageContainer> container;
   ImgDrawResult drawResult = mImage->GetImageContainerAtSize(
-      aManager, decodeSize, svgContext, flags, getter_AddRefs(container));
+      aManager->LayerManager(), decodeSize, svgContext, flags,
+      getter_AddRefs(container));
   if (!container) {
     return drawResult;
   }
 
   mozilla::wr::ImageRendering rendering = wr::ToImageRendering(
       nsLayoutUtils::GetSamplingFilterForFrame(aItem->Frame()));
   gfx::IntSize size;
   Maybe<wr::ImageKey> key = aManager->CommandBuilder().CreateImageKey(
@@ -460,17 +461,17 @@ ImgDrawResult BulletRenderer::CreateWebR
 
   return drawResult;
 }
 
 bool BulletRenderer::CreateWebRenderCommandsForPath(
     nsDisplayItem* aItem, wr::DisplayListBuilder& aBuilder,
     wr::IpcResourceUpdateQueue& aResources,
     const layers::StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   MOZ_ASSERT(IsPathType());
   wr::LayoutRect dest = wr::ToRoundedLayoutRect(mPathRect);
   auto color = wr::ToColorF(ToDeviceColor(mColor));
   bool isBackfaceVisible = !aItem->BackfaceIsHidden();
   switch (mListStyleType) {
     case NS_STYLE_LIST_STYLE_CIRCLE: {
       LayoutDeviceSize radii = mPathRect.Size() / 2.0;
@@ -506,17 +507,17 @@ bool BulletRenderer::CreateWebRenderComm
 
   return true;
 }
 
 bool BulletRenderer::CreateWebRenderCommandsForText(
     nsDisplayItem* aItem, wr::DisplayListBuilder& aBuilder,
     wr::IpcResourceUpdateQueue& aResources,
     const layers::StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   MOZ_ASSERT(IsTextType());
 
   bool dummy;
   nsRect bounds = aItem->GetBounds(aDisplayListBuilder, &dummy);
 
   if (bounds.IsEmpty()) {
     return true;
@@ -545,17 +546,17 @@ class nsDisplayBullet final : public nsD
                            bool* aSnap) const override {
     *aSnap = false;
     return mFrame->GetVisualOverflowRectRelativeToSelf() + ToReferenceFrame();
   }
 
   virtual bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue&, const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
   virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
                        HitTestState* aState,
                        nsTArray<nsIFrame*>* aOutFrames) override {
     aOutFrames->AppendElement(mFrame);
   }
   virtual void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
@@ -598,17 +599,17 @@ class nsDisplayBullet final : public nsD
 
  protected:
   Maybe<BulletRenderer> mBulletRenderer;
 };
 
 bool nsDisplayBullet::CreateWebRenderCommands(
     wr::DisplayListBuilder& aBuilder, wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   // FIXME: avoid needing to make this target if we're drawing text
   // (non-trivial refactor of all this code)
   RefPtr<gfxContext> screenRefCtx = gfxContext::CreateOrNull(
       gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget().get());
   Maybe<BulletRenderer> br =
       static_cast<nsBulletFrame*>(mFrame)->CreateBulletRenderer(
           *screenRefCtx, ToReferenceFrame());
--- a/layout/generic/nsCanvasFrame.cpp
+++ b/layout/generic/nsCanvasFrame.cpp
@@ -22,17 +22,17 @@
 #include "nsCSSFrameConstructor.h"
 #include "nsFrameManager.h"
 #include "gfxPlatform.h"
 #include "nsPrintfCString.h"
 #include "mozilla/AccessibleCaretEventHub.h"
 #include "mozilla/ComputedStyle.h"
 #include "mozilla/dom/AnonymousContent.h"
 #include "mozilla/layers/StackingContextHelper.h"
-#include "mozilla/layers/WebRenderLayerManager.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/PresShell.h"
 // for focus
 #include "nsIScrollableFrame.h"
 #ifdef DEBUG_CANVAS_FOCUS
 #include "nsIDocShell.h"
 #endif
 
 //#define DEBUG_CANVAS_FOCUS
@@ -356,17 +356,17 @@ already_AddRefed<Layer> nsDisplayCanvasB
       aContainerParameters.mOffset.x, aContainerParameters.mOffset.y, 0));
 
   return layer.forget();
 }
 
 bool nsDisplayCanvasBackgroundColor::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
-    const StackingContextHelper& aSc, WebRenderLayerManager* aManager,
+    const StackingContextHelper& aSc, RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   ContainerLayerParameters parameter;
 
   nsCanvasFrame* frame = static_cast<nsCanvasFrame*>(mFrame);
   nsPoint offset = ToReferenceFrame();
   nsRect bgClipRect = frame->CanvasArea() + offset;
   int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
 
--- a/layout/generic/nsCanvasFrame.h
+++ b/layout/generic/nsCanvasFrame.h
@@ -164,17 +164,17 @@ class nsDisplayCanvasBackgroundColor fin
   }
   virtual already_AddRefed<Layer> BuildLayer(
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aContainerParameters) override;
   virtual bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   virtual LayerState GetLayerState(
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aParameters) override {
     if (ForceActiveLayers()) {
       return mozilla::LAYER_ACTIVE;
     }
     return mozilla::LAYER_NONE;
--- a/layout/generic/nsColumnSetFrame.cpp
+++ b/layout/generic/nsColumnSetFrame.cpp
@@ -42,17 +42,17 @@ class nsDisplayColumnRule : public nsDis
     return static_cast<nsColumnSetFrame*>(mFrame)->CalculateColumnRuleBounds(
         ToReferenceFrame());
   }
 
   virtual bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   virtual void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
 
   NS_DISPLAY_DECL_NAME("ColumnRule", TYPE_COLUMN_RULE);
 
  private:
   nsTArray<nsCSSBorderRenderer> mBorderRenderers;
 };
@@ -67,17 +67,17 @@ void nsDisplayColumnRule::Paint(nsDispla
     iter->DrawBorders();
   }
 }
 
 bool nsDisplayColumnRule::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   RefPtr<gfxContext> screenRefCtx = gfxContext::CreateOrNull(
       gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget().get());
 
   static_cast<nsColumnSetFrame*>(mFrame)->CreateBorderRenderers(
       mBorderRenderers, screenRefCtx, GetPaintRect(), ToReferenceFrame());
 
   if (mBorderRenderers.IsEmpty()) {
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -2049,17 +2049,17 @@ class nsDisplaySelectionOverlay : public
   }
 #endif
 
   virtual void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   NS_DISPLAY_DECL_NAME("SelectionOverlay", TYPE_SELECTION_OVERLAY)
  private:
   Color ComputeColor() const;
 
   static Color ComputeColorFromSelectionStyle(ComputedStyle&);
   static Color ApplyTransparencyIfNecessary(nscolor);
 
@@ -2114,17 +2114,17 @@ void nsDisplaySelectionOverlay::Paint(ns
 
   aDrawTarget.FillRect(rect, color);
 }
 
 bool nsDisplaySelectionOverlay::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   wr::LayoutRect bounds =
       wr::ToRoundedLayoutRect(LayoutDeviceRect::FromAppUnits(
           nsRect(ToReferenceFrame(), Frame()->GetSize()),
           mFrame->PresContext()->AppUnitsPerDevPixel()));
   aBuilder.PushRect(bounds, bounds, !BackfaceIsHidden(),
                     wr::ToColorF(ComputeColor()));
   return true;
--- a/layout/generic/nsHTMLCanvasFrame.cpp
+++ b/layout/generic/nsHTMLCanvasFrame.cpp
@@ -8,17 +8,17 @@
 
 #include "nsHTMLCanvasFrame.h"
 
 #include "nsGkAtoms.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/dom/HTMLCanvasElement.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
 #include "mozilla/layers/WebRenderCanvasRenderer.h"
-#include "mozilla/layers/WebRenderLayerManager.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "nsDisplayList.h"
 #include "nsLayoutUtils.h"
 #include "nsStyleUtil.h"
 #include "ImageLayers.h"
 #include "Layers.h"
 #include "ActiveLayerTracker.h"
 
 #include <algorithm>
@@ -110,17 +110,17 @@ class nsDisplayCanvas final : public nsD
       const ContainerLayerParameters& aContainerParameters) override {
     return static_cast<nsHTMLCanvasFrame*>(mFrame)->BuildLayer(
         aBuilder, aManager, this, aContainerParameters);
   }
 
   virtual bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       wr::IpcResourceUpdateQueue& aResources, const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override {
     HTMLCanvasElement* element =
         static_cast<HTMLCanvasElement*>(mFrame->GetContent());
     element->HandlePrintCallback(mFrame->PresContext()->Type());
 
     switch (element->GetCurrentContextType()) {
       case CanvasContextType::Canvas2D:
       case CanvasContextType::WebGL1:
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -17,16 +17,17 @@
 #include "mozilla/Encoding.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/Helpers.h"
 #include "mozilla/gfx/PathHelpers.h"
 #include "mozilla/dom/GeneratedImageContent.h"
 #include "mozilla/dom/HTMLImageElement.h"
 #include "mozilla/dom/ResponsiveImageSelector.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/layers/WebRenderLayerManager.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Unused.h"
 
 #include "nsCOMPtr.h"
 #include "nsFontMetrics.h"
 #include "nsIImageLoadingContent.h"
 #include "nsImageLoadingContent.h"
@@ -1316,17 +1317,17 @@ class nsDisplayAltFeedback final : publi
 
     nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, result);
   }
 
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override {
     uint32_t flags = imgIContainer::FLAG_ASYNC_NOTIFY;
     nsImageFrame* f = static_cast<nsImageFrame*>(mFrame);
     ImgDrawResult result = f->DisplayAltFeedbackWithoutLayer(
         this, aBuilder, aResources, aSc, aManager, aDisplayListBuilder,
         ToReferenceFrame(), flags);
 
     return result == ImgDrawResult::SUCCESS;
@@ -1488,17 +1489,17 @@ ImgDrawResult nsImageFrame::DisplayAltFe
 
   return result;
 }
 
 ImgDrawResult nsImageFrame::DisplayAltFeedbackWithoutLayer(
     nsDisplayItem* aItem, mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder, nsPoint aPt, uint32_t aFlags) {
   // We should definitely have a gIconLoad here.
   MOZ_ASSERT(gIconLoad, "How did we succeed in Init then?");
 
   // Whether we draw the broken or loading icon.
   bool isLoading = IMAGE_OK(GetContent()->AsElement()->State(), true);
 
   // Calculate the inner area
@@ -1620,17 +1621,17 @@ ImgDrawResult nsImageFrame::DisplayAltFe
       const LayoutDeviceRect destRect(
           LayoutDeviceRect::FromAppUnits(dest, factor));
       Maybe<SVGImageContext> svgContext;
       IntSize decodeSize =
           nsLayoutUtils::ComputeImageContainerDrawingParameters(
               imgCon, this, destRect, aSc, aFlags, svgContext);
       RefPtr<ImageContainer> container;
       result = imgCon->GetImageContainerAtSize(
-          aManager, decodeSize, svgContext, aFlags, getter_AddRefs(container));
+          aManager->LayerManager(), decodeSize, svgContext, aFlags, getter_AddRefs(container));
       if (container) {
         bool wrResult = aManager->CommandBuilder().PushImage(
             aItem, container, aBuilder, aResources, aSc, destRect, bounds);
         result &= wrResult ? ImgDrawResult::SUCCESS : ImgDrawResult::NOT_READY;
       } else {
         // We don't use &= here because we want the result to be NOT_READY so
         // the next block executes.
         result = ImgDrawResult::NOT_READY;
@@ -1873,17 +1874,17 @@ already_AddRefed<Layer> nsDisplayImage::
   layer->SetContainer(container);
   ConfigureLayer(layer, aParameters);
   return layer.forget();
 }
 
 bool nsDisplayImage::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
-    const StackingContextHelper& aSc, WebRenderLayerManager* aManager,
+    const StackingContextHelper& aSc, RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   if (!mImage) {
     return false;
   }
 
   MOZ_ASSERT(mFrame->IsImageFrame() || mFrame->IsImageControlFrame());
   // Image layer doesn't support draw focus ring for image map.
   nsImageFrame* frame = static_cast<nsImageFrame*>(mFrame);
@@ -1903,30 +1904,31 @@ bool nsDisplayImage::CreateWebRenderComm
   const LayoutDeviceRect destRect(
       LayoutDeviceRect::FromAppUnits(GetDestRect(), factor));
   Maybe<SVGImageContext> svgContext;
   IntSize decodeSize = nsLayoutUtils::ComputeImageContainerDrawingParameters(
       mImage, mFrame, destRect, aSc, flags, svgContext);
 
   RefPtr<layers::ImageContainer> container;
   ImgDrawResult drawResult = mImage->GetImageContainerAtSize(
-      aManager, decodeSize, svgContext, flags, getter_AddRefs(container));
+      aManager->LayerManager(), decodeSize, svgContext, flags,
+      getter_AddRefs(container));
 
   // While we got a container, it may not contain a fully decoded surface. If
   // that is the case, and we have an image we were previously displaying which
   // has a fully decoded surface, then we should prefer the previous image.
   bool updatePrevImage = false;
   switch (drawResult) {
     case ImgDrawResult::NOT_READY:
     case ImgDrawResult::INCOMPLETE:
     case ImgDrawResult::TEMPORARY_ERROR:
       if (mPrevImage && mPrevImage != mImage) {
         RefPtr<ImageContainer> prevContainer;
         drawResult = mPrevImage->GetImageContainerAtSize(
-            aManager, decodeSize, svgContext, flags,
+            aManager->LayerManager(), decodeSize, svgContext, flags,
             getter_AddRefs(prevContainer));
         if (prevContainer && drawResult == ImgDrawResult::SUCCESS) {
           container = std::move(prevContainer);
           break;
         }
 
         // Previous image was unusable; we can forget about it.
         updatePrevImage = true;
--- a/layout/generic/nsImageFrame.h
+++ b/layout/generic/nsImageFrame.h
@@ -149,17 +149,17 @@ class nsImageFrame : public nsAtomicCont
   ImgDrawResult DisplayAltFeedback(gfxContext& aRenderingContext,
                                    const nsRect& aDirtyRect, nsPoint aPt,
                                    uint32_t aFlags);
 
   ImgDrawResult DisplayAltFeedbackWithoutLayer(
       nsDisplayItem* aItem, mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const mozilla::layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder, nsPoint aPt, uint32_t aFlags);
 
   nsRect GetInnerArea() const;
 
   /**
    * Return a map element associated with this image.
    */
   mozilla::dom::Element* GetMapElement() const;
@@ -485,17 +485,17 @@ class nsDisplayImage final : public nsDi
 
   virtual already_AddRefed<Layer> BuildLayer(
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aContainerParameters) override;
   virtual bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
   NS_DISPLAY_DECL_NAME("Image", TYPE_IMAGE)
  private:
   nsCOMPtr<imgIContainer> mImage;
   nsCOMPtr<imgIContainer> mPrevImage;
 };
 
--- a/layout/generic/nsPluginFrame.cpp
+++ b/layout/generic/nsPluginFrame.cpp
@@ -51,17 +51,17 @@
 #ifdef XP_WIN
 #include "gfxWindowsNativeDrawing.h"
 #include "gfxWindowsSurface.h"
 #endif
 
 #include "Layers.h"
 #include "ReadbackLayer.h"
 #include "ImageContainer.h"
-#include "mozilla/layers/WebRenderLayerManager.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 
 // accessibility support
 #ifdef ACCESSIBILITY
 #include "nsAccessibilityService.h"
 #endif
 
 #include "mozilla/Logging.h"
 
@@ -975,17 +975,17 @@ nsRegion nsDisplayPlugin::GetOpaqueRegio
 
   return result;
 }
 
 bool nsDisplayPlugin::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   return static_cast<nsPluginFrame*>(mFrame)->CreateWebRenderCommands(
       this, aBuilder, aResources, aSc, aManager, aDisplayListBuilder);
 }
 
 nsresult nsPluginFrame::PluginEventNotifier::Run() {
   nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
   obsSvc->NotifyObservers(nullptr, "plugin-changed-event", mEventType.get());
@@ -1299,17 +1299,17 @@ bool nsPluginFrame::GetBounds(nsDisplayI
 
   return true;
 }
 
 bool nsPluginFrame::CreateWebRenderCommands(
     nsDisplayItem* aItem, mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   IntSize size;
   gfxRect r;
   if (!GetBounds(aItem, size, r)) {
     return true;
   }
 
   RefPtr<ImageContainer> container;
--- a/layout/generic/nsPluginFrame.h
+++ b/layout/generic/nsPluginFrame.h
@@ -57,17 +57,17 @@ class nsPluginFrame final : public nsFra
   typedef mozilla::LayerState LayerState;
   typedef mozilla::LayoutDeviceIntPoint LayoutDeviceIntPoint;
   typedef mozilla::LayoutDeviceIntRect LayoutDeviceIntRect;
   typedef mozilla::LayoutDeviceIntRegion LayoutDeviceIntRegion;
   typedef mozilla::layers::Layer Layer;
   typedef mozilla::layers::LayerManager LayerManager;
   typedef mozilla::layers::ImageContainer ImageContainer;
   typedef mozilla::layers::StackingContextHelper StackingContextHelper;
-  typedef mozilla::layers::WebRenderLayerManager WebRenderLayerManager;
+  typedef mozilla::layers::RenderRootStateManager RenderRootStateManager;
   typedef mozilla::layers::WebRenderParentCommand WebRenderParentCommand;
   typedef mozilla::ContainerLayerParameters ContainerLayerParameters;
 
   NS_DECL_FRAMEARENA_HELPERS(nsPluginFrame)
   NS_DECL_QUERYFRAME
 
   friend nsIFrame* NS_NewObjectFrame(nsIPresShell* aPresShell,
                                      ComputedStyle* aStyle);
@@ -218,22 +218,22 @@ class nsPluginFrame final : public nsFra
   void HandleWheelEventAsDefaultAction(mozilla::WidgetWheelEvent* aEvent);
 
   /**
    * WantsToHandleWheelEventAsDefaultAction() returns true if the plugin
    * may want to handle wheel events as default action.
    */
   bool WantsToHandleWheelEventAsDefaultAction() const;
 
-  bool CreateWebRenderCommands(nsDisplayItem* aItem,
-                               mozilla::wr::DisplayListBuilder& aBuilder,
-                               mozilla::wr::IpcResourceUpdateQueue& aResources,
-                               const StackingContextHelper& aSc,
-                               mozilla::layers::WebRenderLayerManager* aManager,
-                               nsDisplayListBuilder* aDisplayListBuilder);
+  bool CreateWebRenderCommands(
+      nsDisplayItem* aItem, mozilla::wr::DisplayListBuilder& aBuilder,
+      mozilla::wr::IpcResourceUpdateQueue& aResources,
+      const StackingContextHelper& aSc,
+      mozilla::layers::RenderRootStateManager* aManager,
+      nsDisplayListBuilder* aDisplayListBuilder);
 
  protected:
   explicit nsPluginFrame(ComputedStyle* aStyle);
   virtual ~nsPluginFrame();
 
   // NOTE:  This frame class does not inherit from |nsLeafFrame|, so
   // this is not a virtual method implementation.
   void GetDesiredSize(nsPresContext* aPresContext,
@@ -392,13 +392,13 @@ class nsDisplayPlugin final : public nsD
       nsDisplayListBuilder* aBuilder) override {
     return new nsDisplayPluginGeometry(this, aBuilder);
   }
 
   virtual bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 };
 
 #endif /* nsPluginFrame_h___ */
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -64,17 +64,17 @@
 #include "nsRange.h"
 #include "nsCSSRendering.h"
 #include "nsContentUtils.h"
 #include "nsLineBreaker.h"
 #include "nsIFrameInlines.h"
 #include "mozilla/intl/WordBreaker.h"
 #include "mozilla/ServoStyleSet.h"
 #include "mozilla/layers/LayersMessages.h"
-#include "mozilla/layers/WebRenderLayerManager.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
 #include "mozilla/webrender/WebRenderAPI.h"
 #include "mozilla/layers/StackingContextHelper.h"
 
 #include <algorithm>
 #include <limits>
 #ifdef ACCESSIBILITY
 #include "nsAccessibilityService.h"
@@ -4872,17 +4872,17 @@ class nsDisplayText final : public nsCha
                HitTestState* aState, nsTArray<nsIFrame*>* aOutFrames) final {
     if (nsRect(ToReferenceFrame(), mFrame->GetSize()).Intersects(aRect)) {
       aOutFrames->AppendElement(mFrame);
     }
   }
   bool CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
                                mozilla::wr::IpcResourceUpdateQueue& aResources,
                                const StackingContextHelper& aSc,
-                               WebRenderLayerManager* aManager,
+                               RenderRootStateManager* aManager,
                                nsDisplayListBuilder* aDisplayListBuilder) final;
   void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) final;
   NS_DISPLAY_DECL_NAME("Text", TYPE_TEXT)
 
   nsRect GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder) const final {
     if (gfxPlatform::GetPlatform()->RespectsFontStyleSmoothing()) {
       // On OS X, web authors can turn off subpixel text rendering using the
       // CSS property -moz-osx-font-smoothing. If they do that, we don't need
@@ -5020,17 +5020,17 @@ void nsDisplayText::Paint(nsDisplayListB
   DrawTargetAutoDisableSubpixelAntialiasing disable(aCtx->GetDrawTarget(),
                                                     mDisableSubpixelAA);
   RenderToContext(aCtx, aBuilder);
 }
 
 bool nsDisplayText::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
-    const StackingContextHelper& aSc, WebRenderLayerManager* aManager,
+    const StackingContextHelper& aSc, RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   if (mBounds.IsEmpty()) {
     return true;
   }
 
   auto appUnitsPerDevPixel = Frame()->PresContext()->AppUnitsPerDevPixel();
   gfx::Point deviceOffset =
       LayoutDevicePoint::FromAppUnits(mBounds.TopLeft(), appUnitsPerDevPixel)
--- a/layout/generic/nsVideoFrame.cpp
+++ b/layout/generic/nsVideoFrame.cpp
@@ -8,17 +8,17 @@
 
 #include "nsVideoFrame.h"
 
 #include "nsCOMPtr.h"
 #include "nsGkAtoms.h"
 
 #include "mozilla/dom/HTMLVideoElement.h"
 #include "mozilla/dom/ShadowRoot.h"
-#include "mozilla/layers/WebRenderLayerManager.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "nsDisplayList.h"
 #include "nsGenericHTMLElement.h"
 #include "nsPresContext.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsBoxLayoutState.h"
 #include "nsBoxFrame.h"
 #include "nsIContentInlines.h"
 #include "nsImageFrame.h"
@@ -431,17 +431,17 @@ class nsDisplayVideo : public nsDisplayI
 #endif
 
   NS_DISPLAY_DECL_NAME("Video", TYPE_VIDEO)
 
   virtual bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const mozilla::layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override {
     nsRect area = Frame()->GetContentRectRelativeToSelf() + ToReferenceFrame();
     HTMLVideoElement* element =
         static_cast<HTMLVideoElement*>(Frame()->GetContent());
 
     nsIntSize videoSizeInPx;
     if (NS_FAILED(element->GetVideoSize(&videoSizeInPx)) || area.IsEmpty()) {
       return true;
--- a/layout/ipc/RenderFrame.cpp
+++ b/layout/ipc/RenderFrame.cpp
@@ -277,17 +277,17 @@ void nsDisplayRemote::Paint(nsDisplayLis
                                                appUnitsPerDevPixel, *target);
   target->DrawDependentSurface(mTabId, destRect);
 }
 
 bool nsDisplayRemote::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   mOffset = GetContentRectLayerOffset(mFrame, aDisplayListBuilder);
 
   LayoutDeviceRect rect = LayoutDeviceRect::FromAppUnits(
       mFrame->GetContentRectRelativeToSelf(),
       mFrame->PresContext()->AppUnitsPerDevPixel());
   rect += mOffset;
 
--- a/layout/ipc/RenderFrame.h
+++ b/layout/ipc/RenderFrame.h
@@ -108,17 +108,17 @@ class nsDisplayRemote final : public nsD
       const ContainerLayerParameters& aContainerParameters) override;
 
   void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
 
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   bool UpdateScrollData(
       mozilla::layers::WebRenderScrollData* aData,
       mozilla::layers::WebRenderLayerScrollData* aLayerData) override;
 
   NS_DISPLAY_DECL_NAME("Remote", TYPE_REMOTE)
 
  private:
--- a/layout/mathml/nsMathMLmtableFrame.cpp
+++ b/layout/mathml/nsMathMLmtableFrame.cpp
@@ -305,17 +305,17 @@ class nsDisplaymtdBorder final : public 
 
     nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, result);
   }
 
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override {
     return false;
   }
 };
 
 #ifdef DEBUG
 #define DEBUG_VERIFY_THAT_FRAME_IS(_frame, _expected)                       \
   MOZ_ASSERT(                                                               \
--- a/layout/painting/nsCSSRendering.cpp
+++ b/layout/painting/nsCSSRendering.cpp
@@ -664,30 +664,30 @@ Maybe<nsCSSBorderRenderer> nsCSSRenderin
       newStyleBorder, aComputedStyle, aOutBorderIsEmpty, aSkipSides);
 }
 
 ImgDrawResult nsCSSRendering::CreateWebRenderCommandsForBorder(
     nsDisplayItem* aItem, nsIFrame* aForFrame, const nsRect& aBorderArea,
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const mozilla::layers::StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   const nsStyleBorder* styleBorder = aForFrame->Style()->StyleBorder();
   return nsCSSRendering::CreateWebRenderCommandsForBorderWithStyleBorder(
       aItem, aForFrame, aBorderArea, aBuilder, aResources, aSc, aManager,
       aDisplayListBuilder, *styleBorder);
 }
 
 ImgDrawResult nsCSSRendering::CreateWebRenderCommandsForBorderWithStyleBorder(
     nsDisplayItem* aItem, nsIFrame* aForFrame, const nsRect& aBorderArea,
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const mozilla::layers::StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder,
     const nsStyleBorder& aStyleBorder) {
   // First try to draw a normal border
   {
     bool borderIsEmpty = false;
     Maybe<nsCSSBorderRenderer> br =
         nsCSSRendering::CreateBorderRendererWithStyleBorder(
             aForFrame->PresContext(), nullptr, aForFrame, nsRect(), aBorderArea,
@@ -1893,17 +1893,17 @@ bool nsCSSRendering::CanBuildWebRenderDi
 
   return false;
 }
 
 ImgDrawResult nsCSSRendering::BuildWebRenderDisplayItemsForStyleImageLayer(
     const PaintBGParams& aParams, mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const mozilla::layers::StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager, nsDisplayItem* aItem) {
+    mozilla::layers::RenderRootStateManager* aManager, nsDisplayItem* aItem) {
   MOZ_ASSERT(aParams.frame,
              "Frame is expected to be provided to "
              "BuildWebRenderDisplayItemsForStyleImageLayer");
 
   ComputedStyle* sc;
   if (!FindBackground(aParams.frame, &sc)) {
     // We don't want to bail out if moz-appearance is set on a root
     // node. If it has a parent content node, bail because it's not
@@ -2618,17 +2618,17 @@ ImgDrawResult nsCSSRendering::PaintStyle
   return result;
 }
 
 ImgDrawResult
 nsCSSRendering::BuildWebRenderDisplayItemsForStyleImageLayerWithSC(
     const PaintBGParams& aParams, mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const mozilla::layers::StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager, nsDisplayItem* aItem,
+    mozilla::layers::RenderRootStateManager* aManager, nsDisplayItem* aItem,
     ComputedStyle* aBackgroundSC, const nsStyleBorder& aBorder) {
   MOZ_ASSERT(!(aParams.paintFlags & PAINTBG_MASK_IMAGE));
 
   nscoord appUnitsPerPixel = aParams.presCtx.AppUnitsPerDevPixel();
   ImageLayerClipState clipState;
 
   clipState.mBGClipArea = *aParams.bgClipRect;
   clipState.mCustomClip = true;
--- a/layout/painting/nsCSSRendering.h
+++ b/layout/painting/nsCSSRendering.h
@@ -33,16 +33,17 @@ struct Color;
 class DrawTarget;
 }  // namespace gfx
 
 namespace layers {
 class ImageContainer;
 class StackingContextHelper;
 class WebRenderParentCommand;
 class LayerManager;
+class RenderRootStateManager;
 }  // namespace layers
 
 namespace wr {
 class DisplayListBuilder;
 }  // namespace wr
 
 enum class PaintBorderFlags : uint8_t { SYNC_DECODE_IMAGES = 1 << 0 };
 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(PaintBorderFlags)
@@ -197,25 +198,25 @@ struct nsCSSRendering {
       nsIFrame* aForFrame, const nsRect& aDirtyRect, const nsRect& aBorderArea,
       mozilla::ComputedStyle* aComputedStyle);
 
   static ImgDrawResult CreateWebRenderCommandsForBorder(
       nsDisplayItem* aItem, nsIFrame* aForFrame, const nsRect& aBorderArea,
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const mozilla::layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder);
 
   static ImgDrawResult CreateWebRenderCommandsForBorderWithStyleBorder(
       nsDisplayItem* aItem, nsIFrame* aForFrame, const nsRect& aBorderArea,
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const mozilla::layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder,
       const nsStyleBorder& aStyleBorder);
 
   /**
    * Render the outline for an element using css rendering rules
    * for borders.
    */
   static void PaintOutline(nsPresContext* aPresContext,
@@ -478,23 +479,23 @@ struct nsCSSRendering {
   static bool CanBuildWebRenderDisplayItemsForStyleImageLayer(
       LayerManager* aManager, nsPresContext& aPresCtx, nsIFrame* aFrame,
       const nsStyleBackground* aBackgroundStyle, int32_t aLayer,
       uint32_t aPaintFlags);
   static ImgDrawResult BuildWebRenderDisplayItemsForStyleImageLayer(
       const PaintBGParams& aParams, mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const mozilla::layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager, nsDisplayItem* aItem);
+      mozilla::layers::RenderRootStateManager* aManager, nsDisplayItem* aItem);
 
   static ImgDrawResult BuildWebRenderDisplayItemsForStyleImageLayerWithSC(
       const PaintBGParams& aParams, mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const mozilla::layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager, nsDisplayItem* aItem,
+      mozilla::layers::RenderRootStateManager* aManager, nsDisplayItem* aItem,
       mozilla::ComputedStyle* mBackgroundSC, const nsStyleBorder& aBorder);
 
   /**
    * Returns the rectangle covered by the given background layer image, taking
    * into account background positioning, sizing, and repetition, but not
    * clipping.
    */
   static nsRect GetBackgroundLayerRect(nsPresContext* aPresContext,
--- a/layout/painting/nsCSSRenderingBorders.cpp
+++ b/layout/painting/nsCSSRenderingBorders.cpp
@@ -25,16 +25,17 @@
 #include "nsExpirationTracker.h"
 #include "nsIScriptError.h"
 #include "nsClassHashtable.h"
 #include "nsPresContext.h"
 #include "nsStyleStruct.h"
 #include "gfx2DGlue.h"
 #include "gfxGradientCache.h"
 #include "mozilla/layers/StackingContextHelper.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/layers/WebRenderLayerManager.h"
 #include "mozilla/Range.h"
 #include <algorithm>
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 using namespace mozilla::image;
 
@@ -3533,17 +3534,17 @@ ImgDrawResult nsCSSBorderImageRenderer::
   return result;
 }
 
 ImgDrawResult nsCSSBorderImageRenderer::CreateWebRenderCommands(
     nsDisplayItem* aItem, nsIFrame* aForFrame,
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const mozilla::layers::StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   if (!mImageRenderer.IsReady()) {
     return ImgDrawResult::NOT_READY;
   }
 
   float widths[4];
   float slice[4];
   float outset[4];
@@ -3579,18 +3580,19 @@ ImgDrawResult nsCSSBorderImageRenderer::
 
       RefPtr<imgIContainer> img = mImageRenderer.GetImage();
       Maybe<SVGImageContext> svgContext;
       gfx::IntSize decodeSize =
           nsLayoutUtils::ComputeImageContainerDrawingParameters(
               img, aForFrame, destRect, aSc, flags, svgContext);
 
       RefPtr<layers::ImageContainer> container;
-      drawResult = img->GetImageContainerAtSize(
-          aManager, decodeSize, svgContext, flags, getter_AddRefs(container));
+      drawResult = img->GetImageContainerAtSize(aManager->LayerManager(),
+                                                decodeSize, svgContext, flags,
+                                                getter_AddRefs(container));
       if (!container) {
         break;
       }
 
       mozilla::wr::ImageRendering rendering = wr::ToImageRendering(
           nsLayoutUtils::GetSamplingFilterForFrame(aItem->Frame()));
       gfx::IntSize size;
       Maybe<wr::ImageKey> key = aManager->CommandBuilder().CreateImageKey(
--- a/layout/painting/nsCSSRenderingBorders.h
+++ b/layout/painting/nsCSSRenderingBorders.h
@@ -270,17 +270,17 @@ class nsCSSBorderImageRenderer final {
                                                 gfxContext& aRenderingContext,
                                                 nsIFrame* aForFrame,
                                                 const nsRect& aDirtyRect);
   mozilla::image::ImgDrawResult CreateWebRenderCommands(
       nsDisplayItem* aItem, nsIFrame* aForFrame,
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const mozilla::layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder);
 
   nsCSSBorderImageRenderer(const nsCSSBorderImageRenderer& aRhs);
   nsCSSBorderImageRenderer& operator=(const nsCSSBorderImageRenderer& aRhs);
 
  private:
   nsCSSBorderImageRenderer(nsIFrame* aForFrame, const nsRect& aBorderArea,
                            const nsStyleBorder& aStyleBorder,
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -88,16 +88,17 @@
 #include "nsDOMTokenList.h"
 #include "nsCSSProps.h"
 #include "nsSVGMaskFrame.h"
 #include "nsTableCellFrame.h"
 #include "nsTableColFrame.h"
 #include "nsTextFrame.h"
 #include "nsSliderFrame.h"
 #include "ClientLayerManager.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/layers/StackingContextHelper.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
 #include "mozilla/layers/WebRenderLayerManager.h"
 #include "mozilla/layers/WebRenderMessages.h"
 #include "mozilla/layers/WebRenderScrollData.h"
 
 using namespace mozilla;
 using namespace mozilla::layers;
@@ -705,26 +706,27 @@ static void AddAnimationsForProperty(
     AddAnimationForProperty(aFrame, *property, anim, aAnimationInfo, data,
                             aSendFlag);
     keyframeEffect->SetIsRunningOnCompositor(aProperty, true);
   }
 }
 
 static uint64_t AddAnimationsForWebRender(
     nsDisplayItem* aItem, nsCSSPropertyID aProperty,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   RefPtr<WebRenderAnimationData> animationData =
       aManager->CommandBuilder()
           .CreateOrRecycleWebRenderUserData<WebRenderAnimationData>(aItem);
   AnimationInfo& animationInfo = animationData->GetAnimationInfo();
   AddAnimationsForProperty(aItem->Frame(), aDisplayListBuilder, aItem,
                            aProperty, animationInfo, Send::Immediate,
                            layers::LayersBackend::LAYERS_WR);
-  animationInfo.StartPendingAnimations(aManager->GetAnimationReadyTime());
+  animationInfo.StartPendingAnimations(
+      aManager->LayerManager()->GetAnimationReadyTime());
 
   // Note that animationsId can be 0 (uninitialized in AnimationInfo) if there
   // are no active animations.
   uint64_t animationsId = animationInfo.GetCompositorAnimationsId();
   if (!animationInfo.GetAnimations().IsEmpty()) {
     OpAddCompositorAnimations anim(
         CompositorAnimations(animationInfo.GetAnimations(), animationsId));
     aManager->WrBridge()->AddWebRenderParentCommand(anim);
@@ -3287,17 +3289,17 @@ void nsDisplaySolidColor::WriteDebugInfo
           << "," << (int)NS_GET_B(mColor) << "," << (int)NS_GET_A(mColor)
           << ")";
 }
 
 bool nsDisplaySolidColor::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   LayoutDeviceRect bounds = LayoutDeviceRect::FromAppUnits(
       mBounds, mFrame->PresContext()->AppUnitsPerDevPixel());
   wr::LayoutRect roundedRect = wr::ToRoundedLayoutRect(bounds);
 
   aBuilder.PushRect(roundedRect, roundedRect, !BackfaceIsHidden(),
                     wr::ToColorF(ToDeviceColor(mColor)));
 
@@ -3326,17 +3328,17 @@ void nsDisplaySolidColorRegion::WriteDeb
   aStream << " (rgba " << int(mColor.r * 255) << "," << int(mColor.g * 255)
           << "," << int(mColor.b * 255) << "," << mColor.a << ")";
 }
 
 bool nsDisplaySolidColorRegion::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   for (auto iter = mRegion.RectIter(); !iter.Done(); iter.Next()) {
     nsRect rect = iter.Get();
     LayoutDeviceRect layerRects = LayoutDeviceRect::FromAppUnits(
         rect, mFrame->PresContext()->AppUnitsPerDevPixel());
     wr::LayoutRect roundedRect = wr::ToRoundedLayoutRect(layerRects);
     aBuilder.PushRect(roundedRect, roundedRect, !BackfaceIsHidden(),
                       wr::ToColorF(ToDeviceColor(mColor)));
@@ -3976,20 +3978,21 @@ bool nsDisplayBackgroundImage::CanBuildW
          nsCSSRendering::CanBuildWebRenderDisplayItemsForStyleImageLayer(
              aManager, *StyleFrame()->PresContext(), StyleFrame(),
              mBackgroundStyle->StyleBackground(), mLayer, mImageFlags);
 }
 
 bool nsDisplayBackgroundImage::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
-    const StackingContextHelper& aSc, WebRenderLayerManager* aManager,
+    const StackingContextHelper& aSc, RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   ContainerLayerParameters parameter;
-  if (!CanBuildWebRenderDisplayItems(aManager, aDisplayListBuilder)) {
+  if (!CanBuildWebRenderDisplayItems(aManager->LayerManager(),
+                                     aDisplayListBuilder)) {
     return false;
   }
 
   CheckForBorderItem(this, mImageFlags);
   nsCSSRendering::PaintBGParams params =
       nsCSSRendering::PaintBGParams::ForSingleLayer(
           *StyleFrame()->PresContext(), GetPaintRect(), mBackgroundRect,
           StyleFrame(), mImageFlags, mLayer, CompositionOp::OP_OVER);
@@ -4333,17 +4336,17 @@ void nsDisplayThemedBackground::PaintInt
   theme->DrawWidgetBackground(aCtx, StyleFrame(), mAppearance, mBackgroundRect,
                               drawing);
 }
 
 bool nsDisplayThemedBackground::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   nsITheme* theme = StyleFrame()->PresContext()->GetTheme();
   return theme->CreateWebRenderCommandsForWidget(aBuilder, aResources, aSc,
                                                  aManager, StyleFrame(),
                                                  mAppearance, mBackgroundRect);
 }
 
 bool nsDisplayThemedBackground::IsWindowActive() const {
@@ -4565,17 +4568,17 @@ already_AddRefed<Layer> nsDisplayBackgro
 
   return layer.forget();
 }
 
 bool nsDisplayBackgroundColor::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   if (mColor == Color()) {
     return true;
   }
 
   StyleGeometryBox clip =
       mBackgroundStyle->StyleBackground()->mImage.mLayers[0].mClip;
   if (clip == StyleGeometryBox::Text) {
@@ -4753,17 +4756,17 @@ already_AddRefed<Layer> nsDisplayClearBa
 
   return layer.forget();
 }
 
 bool nsDisplayClearBackground::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   LayoutDeviceRect bounds = LayoutDeviceRect::FromAppUnits(
       nsRect(ToReferenceFrame(), mFrame->GetSize()),
       mFrame->PresContext()->AppUnitsPerDevPixel());
 
   aBuilder.PushClearRect(wr::ToRoundedLayoutRect(bounds));
 
   return true;
@@ -4785,17 +4788,17 @@ void nsDisplayOutline::Paint(nsDisplayLi
       mFrame->PresContext(), *aCtx, mFrame, GetPaintRect(),
       nsRect(offset, mFrame->GetSize()), mFrame->Style());
 }
 
 bool nsDisplayOutline::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   ContainerLayerParameters parameter;
 
   const auto& outlineStyle = mFrame->StyleOutline()->mOutlineStyle;
   if (outlineStyle.IsAuto() && nsLayoutUtils::IsOutlineStyleAutoEnabled()) {
     nsITheme* theme = mFrame->PresContext()->GetTheme();
     if (theme && theme->ThemeSupportsWidget(mFrame->PresContext(), mFrame,
                                             StyleAppearance::FocusOutline)) {
@@ -4845,17 +4848,17 @@ void nsDisplayEventReceiver::HitTest(nsD
 
   aOutFrames->AppendElement(mFrame);
 }
 
 bool nsDisplayEventReceiver::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   // This display item should never be getting created when building a display
   // list for WebRender consumption, so this function should never get called.
   MOZ_ASSERT(false);
   return true;
 }
 
 nsDisplayCompositorHitTestInfo::nsDisplayCompositorHitTestInfo(
@@ -4900,17 +4903,17 @@ void nsDisplayCompositorHitTestInfo::Ini
     mScrollTarget = mozilla::Some(aBuilder->GetCurrentScrollbarTarget());
   }
 }
 
 bool nsDisplayCompositorHitTestInfo::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   if (HitTestArea().IsEmpty()) {
     return true;
   }
 
   // XXX: eventually this scrollId computation and the SetHitTestInfo
   // call will get moved out into the WR display item iteration code so that
   // we don't need to do it as often, and so that we can do it for other
@@ -4981,17 +4984,17 @@ void nsDisplayCaret::Paint(nsDisplayList
   // need to check for the caret's visibility.
   mCaret->PaintCaret(*aCtx->GetDrawTarget(), mFrame, ToReferenceFrame());
 }
 
 bool nsDisplayCaret::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   using namespace mozilla::layers;
   int32_t contentOffset;
   nsIFrame* frame = mCaret->GetFrame(&contentOffset);
   if (!frame) {
     return true;
   }
   NS_ASSERTION(frame == mFrame, "We're referring different frame");
@@ -5075,17 +5078,17 @@ LayerState nsDisplayBorder::GetLayerStat
     const ContainerLayerParameters& aParameters) {
   return LAYER_NONE;
 }
 
 bool nsDisplayBorder::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   nsRect rect = nsRect(ToReferenceFrame(), mFrame->GetSize());
 
   ImgDrawResult drawResult = nsCSSRendering::CreateWebRenderCommandsForBorder(
       this, mFrame, rect, aBuilder, aResources, aSc, aManager,
       aDisplayListBuilder);
 
   if (drawResult == ImgDrawResult::NOT_SUPPORTED) {
@@ -5217,17 +5220,17 @@ bool nsDisplayBoxShadowOuter::CanBuildWe
 
   return true;
 }
 
 bool nsDisplayBoxShadowOuter::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   if (!CanBuildWebRenderDisplayItems()) {
     return false;
   }
 
   int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
   nsPoint offset = ToReferenceFrame();
   nsRect borderRect = mFrame->VisualBorderRectRelativeToSelf() + offset;
@@ -5434,17 +5437,17 @@ nsDisplayBoxShadowInner::CreateInsetBoxS
     }
   }
 }
 
 bool nsDisplayBoxShadowInner::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   if (!CanCreateWebRenderCommands(aDisplayListBuilder, mFrame,
                                   ToReferenceFrame())) {
     return false;
   }
 
   bool snap;
   nsRegion visible = GetBounds(aDisplayListBuilder, &snap);
@@ -5699,17 +5702,17 @@ void nsDisplayWrapList::SetReferenceFram
   mReferenceFrame = aFrame;
   mToReferenceFrame = mFrame->GetOffsetToCrossDoc(mReferenceFrame);
 }
 
 bool nsDisplayWrapList::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   aManager->CommandBuilder().CreateWebRenderCommandsFromDisplayList(
       GetChildren(), this, aDisplayListBuilder, aSc, aBuilder, aResources);
   return true;
 }
 
 static nsresult WrapDisplayList(nsDisplayListBuilder* aBuilder,
                                 nsIFrame* aFrame, nsDisplayList* aList,
@@ -6051,17 +6054,17 @@ void nsDisplayOpacity::ComputeInvalidati
 void nsDisplayOpacity::WriteDebugInfo(std::stringstream& aStream) {
   aStream << " (opacity " << mOpacity << ")";
 }
 
 bool nsDisplayOpacity::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   float* opacityForSC = &mOpacity;
 
   uint64_t animationsId = AddAnimationsForWebRender(
       this, eCSSProperty_opacity, aManager, aDisplayListBuilder);
   wr::WrAnimationProperty prop{
       wr::WrAnimationType::Opacity,
       animationsId,
@@ -6099,17 +6102,17 @@ LayerState nsDisplayBlendMode::GetLayerS
     const ContainerLayerParameters& aParameters) {
   return LAYER_ACTIVE;
 }
 
 bool nsDisplayBlendMode::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   nsTArray<mozilla::wr::WrFilterOp> filters;
   StackingContextHelper sc(aSc, GetActiveScrolledRoot(), mFrame, this, aBuilder,
                            filters, LayoutDeviceRect(), nullptr, nullptr,
                            nullptr, nullptr, nullptr,
                            nsCSSRendering::GetGFXBlendMode(mBlendMode));
 
   return nsDisplayWrapList::CreateWebRenderCommands(
@@ -6221,17 +6224,17 @@ LayerState nsDisplayBlendContainer::GetL
   return RequiredLayerStateForChildren(aBuilder, aManager, aParameters, mList,
                                        GetAnimatedGeometryRoot());
 }
 
 bool nsDisplayBlendContainer::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   StackingContextHelper sc(aSc, GetActiveScrolledRoot(), mFrame, this,
                            aBuilder);
 
   return nsDisplayWrapList::CreateWebRenderCommands(
       aBuilder, aResources, sc, aManager, aDisplayListBuilder);
 }
 
@@ -6310,19 +6313,20 @@ already_AddRefed<Layer> nsDisplayOwnLaye
     mFrame->PresContext()->SetNotifySubDocInvalidationData(layer);
   }
   return layer.forget();
 }
 
 bool nsDisplayOwnLayer::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
-    const StackingContextHelper& aSc, WebRenderLayerManager* aManager,
+    const StackingContextHelper& aSc, RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
-  if (!aManager->AsyncPanZoomEnabled() || !IsScrollThumbLayer()) {
+  if (!aManager->LayerManager()->AsyncPanZoomEnabled() ||
+      !IsScrollThumbLayer()) {
     return nsDisplayWrapList::CreateWebRenderCommands(
         aBuilder, aResources, aSc, aManager, aDisplayListBuilder);
   }
 
   // APZ is enabled and this is a scroll thumb, so we need to create and
   // set an animation id. That way APZ can move this scrollthumb around as
   // needed.
   RefPtr<WebRenderAnimationData> animationData =
@@ -6673,17 +6677,17 @@ ViewID nsDisplayFixedPosition::GetScroll
   }
   return nsLayoutUtils::ScrollIdForRootScrollFrame(mFrame->PresContext());
 }
 
 bool nsDisplayFixedPosition::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   // We install this RAII scrolltarget tracker so that any
   // nsDisplayCompositorHitTestInfo items inside this fixed-pos item (and that
   // share the same ASR as this item) use the correct scroll target. That way
   // attempts to scroll on those items will scroll the root scroll frame.
   mozilla::wr::DisplayListBuilder::FixedPosScrollTargetTracker tracker(
       aBuilder, GetActiveScrolledRoot(), GetScrollTargetId());
   return nsDisplayOwnLayer::CreateWebRenderCommands(
@@ -6849,17 +6853,17 @@ static nscoord DistanceToRange(nscoord m
   }
   MOZ_ASSERT(min <= 0 && max >= 0);
   return 0;
 }
 
 bool nsDisplayStickyPosition::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
-    const StackingContextHelper& aSc, WebRenderLayerManager* aManager,
+    const StackingContextHelper& aSc, RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   StickyScrollContainer* stickyScrollContainer =
       StickyScrollContainer::GetStickyScrollContainerForFrame(mFrame);
   if (stickyScrollContainer) {
     // If there's no ASR for the scrollframe that this sticky item is attached
     // to, then don't create a WR sticky item for it either. Trying to do so
     // will end in sadness because WR will interpret some coordinates as
     // relative to the nearest enclosing scrollframe, which will correspond
@@ -7823,17 +7827,17 @@ bool nsDisplayTransform::ShouldBuildLaye
   // result.  It should always build a layer to make sure it is
   // rendering correctly.
   return MayBeAnimated(aBuilder) || mFrame->Combines3DTransformWithAncestors();
 }
 
 bool nsDisplayTransform::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
-    const StackingContextHelper& aSc, WebRenderLayerManager* aManager,
+    const StackingContextHelper& aSc, RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   // We want to make sure we don't pollute the transform property in the WR
   // stacking context by including the position of this frame (relative to the
   // parent reference frame). We need to keep those separate; the position of
   // this frame goes into the stacking context bounds while the transform goes
   // into the transform.
   LayoutDevicePoint position;
   Matrix4x4 newTransformMatrix = GetTransformForRendering(&position);
@@ -8420,17 +8424,17 @@ LayerState nsDisplayPerspective::GetLaye
     nsDisplayListBuilder* aBuilder, LayerManager* aManager,
     const ContainerLayerParameters& aParameters) {
   return LAYER_ACTIVE_FORCE;
 }
 
 bool nsDisplayPerspective::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
-    const StackingContextHelper& aSc, WebRenderLayerManager* aManager,
+    const StackingContextHelper& aSc, RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   float appUnitsPerPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
   Matrix4x4 perspectiveMatrix;
   DebugOnly<bool> hasPerspective = nsDisplayTransform::ComputePerspectiveMatrix(
       mFrame, appUnitsPerPixel, perspectiveMatrix);
   MOZ_ASSERT(hasPerspective, "Why did we create nsDisplayPerspective?");
 
   /*
@@ -9003,17 +9007,17 @@ static Maybe<wr::WrClipId> CreateSimpleC
 enum class HandleOpacity {
   No,
   Yes,
 };
 
 static Maybe<Pair<wr::WrClipId, HandleOpacity>> CreateWRClipPathAndMasks(
     nsDisplayMasksAndClipPaths* aDisplayItem, const LayoutDeviceRect& aBounds,
     wr::IpcResourceUpdateQueue& aResources, wr::DisplayListBuilder& aBuilder,
-    const StackingContextHelper& aSc, layers::WebRenderLayerManager* aManager,
+    const StackingContextHelper& aSc, layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   if (auto clip = CreateSimpleClipRegion(*aDisplayItem, aBuilder)) {
     return Some(MakePair(*clip, HandleOpacity::Yes));
   }
 
   Maybe<wr::WrImageMask> mask = aManager->CommandBuilder().BuildWrMaskImage(
       aDisplayItem, aBuilder, aResources, aSc, aDisplayListBuilder, aBounds);
   if (!mask) {
@@ -9025,17 +9029,17 @@ static Maybe<Pair<wr::WrClipId, HandleOp
 
   return Some(MakePair(clipId, HandleOpacity::No));
 }
 
 bool nsDisplayMasksAndClipPaths::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   bool snap;
   auto appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
   nsRect displayBounds = GetBounds(aDisplayListBuilder, &snap);
   LayoutDeviceRect bounds =
       LayoutDeviceRect::FromAppUnits(displayBounds, appUnitsPerDevPixel);
 
   Maybe<Pair<wr::WrClipId, HandleOpacity>> clip = CreateWRClipPathAndMasks(
@@ -9314,17 +9318,17 @@ bool nsDisplayFilters::CreateWebRenderCS
 
   return true;
 }
 
 bool nsDisplayFilters::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   bool snap;
   float auPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
   nsRect displayBounds = GetBounds(aDisplayListBuilder, &snap);
   auto postFilterBounds = LayoutDeviceIntRect::Round(
       LayoutDeviceRect::FromAppUnits(displayBounds, auPerDevPixel));
   auto preFilterBounds = LayoutDeviceIntRect::Round(
       LayoutDeviceRect::FromAppUnits(mBounds, auPerDevPixel));
@@ -9415,17 +9419,17 @@ already_AddRefed<Layer> nsDisplaySVGWrap
 
   return container.forget();
 }
 
 bool nsDisplaySVGWrapper::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   if (gfxPrefs::WebRenderBlobInvalidation()) {
     return nsDisplayWrapList::CreateWebRenderCommands(
         aBuilder, aResources, aSc, aManager, aDisplayListBuilder);
   }
 
   return false;
 }
@@ -9476,17 +9480,17 @@ already_AddRefed<Layer> nsDisplayForeign
 
   return container.forget();
 }
 
 bool nsDisplayForeignObject::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   if (gfxPrefs::WebRenderBlobInvalidation()) {
     AutoRestore<bool> restoreDoGrouping(aManager->CommandBuilder().mDoGrouping);
     aManager->CommandBuilder().mDoGrouping = false;
     return nsDisplayWrapList::CreateWebRenderCommands(
         aBuilder, aResources, aSc, aManager, aDisplayListBuilder);
   } else {
     return false;
--- a/layout/painting/nsDisplayList.h
+++ b/layout/painting/nsDisplayList.h
@@ -65,16 +65,17 @@ class nsDisplayScrollInfoLayer;
 class nsCaret;
 enum class nsDisplayOwnLayerFlags;
 
 namespace mozilla {
 class FrameLayerBuilder;
 struct MotionPathData;
 namespace layers {
 struct FrameMetrics;
+class RenderRootStateManager;
 class Layer;
 class ImageLayer;
 class ImageContainer;
 class StackingContextHelper;
 class WebRenderCommand;
 class WebRenderScrollData;
 class WebRenderLayerScrollData;
 }  // namespace layers
@@ -2528,17 +2529,17 @@ class nsDisplayItem : public nsDisplayIt
    * not active.
    *
    * @return true if successfully creating webrender commands.
    */
   virtual bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) {
     return false;
   }
 
   /**
    * Updates the provided aLayerData with any APZ-relevant scroll data
    * that is specific to this display item. This is stuff that would normally
    * be put on the layer during BuildLayer, but this is only called in
@@ -3842,17 +3843,17 @@ class nsDisplayCaret : public nsDisplayI
   NS_DISPLAY_DECL_NAME("Caret", TYPE_CARET)
 
   nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) const override;
   void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
  protected:
   RefPtr<nsCaret> mCaret;
   nsRect mBounds;
 };
 
 /**
@@ -3872,17 +3873,17 @@ class nsDisplayBorder : public nsDisplay
   nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) const override;
   LayerState GetLayerState(
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aParameters) override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
   nsDisplayItemGeometry* AllocateGeometry(
       nsDisplayListBuilder* aBuilder) override;
   void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
                                  const nsDisplayItemGeometry* aGeometry,
                                  nsRegion* aInvalidRegion) const override;
 
@@ -4038,17 +4039,17 @@ class nsDisplaySolidColor : public nsDis
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aContainerParameters) override;
   void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
   void WriteDebugInfo(std::stringstream& aStream) override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   bool CanBeReused() const override { return mCanBeReused; }
 
   int32_t ZIndex() const override {
     if (mOverrideZIndex) {
       return mOverrideZIndex.value();
     }
     return nsDisplaySolidColorBase::ZIndex();
@@ -4108,17 +4109,17 @@ class nsDisplaySolidColorRegion : public
       aInvalidRegion->Or(geometry->mRegion.GetBounds(), mRegion.GetBounds());
     }
   }
 
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
  protected:
   nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) const override;
   void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
   void WriteDebugInfo(std::stringstream& aStream) override;
 
  private:
@@ -4183,17 +4184,17 @@ class nsDisplayBackgroundImage : public 
       const ContainerLayerParameters& aParameters) override;
   already_AddRefed<Layer> BuildLayer(
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aContainerParameters) override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
                HitTestState* aState, nsTArray<nsIFrame*>* aOutFrames) override;
   bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
                          nsRegion* aVisibleRegion) override;
   nsRegion GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
                            bool* aSnap) const override;
   mozilla::Maybe<nscolor> IsUniform(
@@ -4409,17 +4410,17 @@ class nsDisplayThemedBackground : public
   nsRegion GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
                            bool* aSnap) const override;
   mozilla::Maybe<nscolor> IsUniform(
       nsDisplayListBuilder* aBuilder) const override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
   bool MustPaintOnContentSide() const override { return true; }
 
   /**
    * GetBounds() returns the background painting area.
    */
   nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) const override;
@@ -4546,17 +4547,17 @@ class nsDisplayBackgroundColor : public 
                      const DisplayItemClip& aClip) override;
   already_AddRefed<Layer> BuildLayer(
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aContainerParameters) override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   nsRegion GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
                            bool* aSnap) const override;
   mozilla::Maybe<nscolor> IsUniform(
       nsDisplayListBuilder* aBuilder) const override;
   void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
                HitTestState* aState, nsTArray<nsIFrame*>* aOutFrames) override;
   void ApplyOpacity(nsDisplayListBuilder* aBuilder, float aOpacity,
@@ -4715,17 +4716,17 @@ class nsDisplayClearBackground : public 
   already_AddRefed<Layer> BuildLayer(
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aContainerParameters) override;
 
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 };
 
 /**
  * The standard display item to paint the outer CSS box-shadows of a frame.
  */
 class nsDisplayBoxShadowOuter final : public nsDisplayItem {
  public:
@@ -4772,17 +4773,17 @@ class nsDisplayBoxShadowOuter final : pu
     return new nsDisplayBoxShadowOuterGeometry(this, aBuilder, mOpacity);
   }
 
   bool CanBuildWebRenderDisplayItems();
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   nsRect GetBoundsInternal();
 
  private:
   nsRegion mVisibleRegion;
   nsRect mBounds;
   float mOpacity;
 };
@@ -4838,17 +4839,17 @@ class nsDisplayBoxShadowInner : public n
   static void CreateInsetBoxShadowWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       const StackingContextHelper& aSc, nsRegion& aVisibleRegion,
       nsIFrame* aFrame, const nsRect& aBorderRect);
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
  private:
   nsRegion mVisibleRegion;
 };
 
 /**
  * The standard display item to paint the CSS outline of a frame.
@@ -4865,17 +4866,17 @@ class nsDisplayOutline : public nsDispla
 #endif
 
   NS_DISPLAY_DECL_NAME("Outline", TYPE_OUTLINE)
 
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   bool IsInvisibleInRect(const nsRect& aRect) const override;
   nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) const override;
   void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
 };
 
 /**
  * A class that lets you receive events within the frame bounds but never
@@ -4895,17 +4896,17 @@ class nsDisplayEventReceiver : public ns
   NS_DISPLAY_DECL_NAME("EventReceiver", TYPE_EVENT_RECEIVER)
 
   void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
                HitTestState* aState, nsTArray<nsIFrame*>* aOutFrames) override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 };
 
 /**
  * Similar to nsDisplayEventReceiver in that it is used for hit-testing. However
  * this gets built when we're doing widget painting and we need to send the
  * compositor some hit-test info for a frame. This is effectively a dummy item
  * whose sole purpose is to carry the hit-test info to the compositor.
@@ -4931,17 +4932,17 @@ class nsDisplayCompositorHitTestInfo : p
   NS_DISPLAY_DECL_NAME("CompositorHitTestInfo", TYPE_COMPOSITOR_HITTEST_INFO)
 
   void InitializeScrollTarget(nsDisplayListBuilder* aBuilder);
 
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   uint32_t GetPerFrameKey() const override;
   int32_t ZIndex() const override;
   void SetOverrideZIndex(int32_t aZIndex);
 
   /**
    * ApplyOpacity() is overriden for opacity flattening.
    */
@@ -5168,17 +5169,17 @@ class nsDisplayWrapList : public nsDispl
     MOZ_ASSERT_UNREACHABLE("We never returned nullptr for GetUnderlyingFrame!");
     return nullptr;
   }
 
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
   const ActiveScrolledRoot* GetFrameActiveScrolledRoot() {
     return mFrameActiveScrolledRoot;
   }
 
  protected:
   void MergeFromTrackingMergedFrames(const nsDisplayWrapList* aOther) {
@@ -5336,17 +5337,17 @@ class nsDisplayOpacity : public nsDispla
   static bool NeedsActiveLayer(nsDisplayListBuilder* aBuilder,
                                nsIFrame* aFrame);
   void WriteDebugInfo(std::stringstream& aStream) override;
   bool CanUseAsyncAnimations(nsDisplayListBuilder* aBuilder) override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
   float GetOpacity() const { return mOpacity; }
 
   bool ForEventsAndPluginsOnly() const { return mForEventsAndPluginsOnly; }
 
  private:
   bool ApplyOpacityToChildren(nsDisplayListBuilder* aBuilder);
@@ -5416,17 +5417,17 @@ class nsDisplayBlendMode : public nsDisp
 
   LayerState GetLayerState(
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aParameters) override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
                          nsRegion* aVisibleRegion) override;
 
   bool CanMerge(const nsDisplayItem* aItem) const override;
 
   bool ShouldFlattenAway(nsDisplayListBuilder* aBuilder) override {
     return false;
@@ -5529,17 +5530,17 @@ class nsDisplayBlendContainer : public n
       const ContainerLayerParameters& aContainerParameters) override;
   LayerState GetLayerState(
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aParameters) override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
   bool CanMerge(const nsDisplayItem* aItem) const override {
     // Items for the same content element should be merged into a single
     // compositing group.
     return HasDifferentFrame(aItem) && HasSameTypeAndClip(aItem) &&
            HasSameContent(aItem) &&
            mIsForBackground ==
@@ -5694,17 +5695,17 @@ class nsDisplayOwnLayer : public nsDispl
       nsDisplayListBuilder* aBuilder) const override;
   already_AddRefed<Layer> BuildLayer(
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aContainerParameters) override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   bool UpdateScrollData(
       mozilla::layers::WebRenderScrollData* aData,
       mozilla::layers::WebRenderLayerScrollData* aLayerData) override;
   LayerState GetLayerState(
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aParameters) override;
 
@@ -5858,17 +5859,17 @@ class nsDisplayStickyPosition : public n
       const ContainerLayerParameters& aParameters) override {
     return mozilla::LAYER_ACTIVE;
   }
 
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
   const ActiveScrolledRoot* GetContainerASR() const { return mContainerASR; }
 
  private:
   // This stores the ASR that this sticky container item would have assuming it
   // has no fixed descendants. This may be the same as the ASR returned by
   // GetActiveScrolledRoot(), or it may be a descendant of that.
@@ -5927,17 +5928,17 @@ class nsDisplayFixedPosition : public ns
   AnimatedGeometryRoot* AnimatedGeometryRootForScrollMetadata() const override {
     return mAnimatedGeometryRootForScrollMetadata;
   }
 
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   bool UpdateScrollData(
       mozilla::layers::WebRenderScrollData* aData,
       mozilla::layers::WebRenderLayerScrollData* aLayerData) override;
   void WriteDebugInfo(std::stringstream& aStream) override;
 
  protected:
   // For background-attachment:fixed
@@ -6250,17 +6251,17 @@ class nsDisplayMasksAndClipPaths : publi
                  bool* aMaskPainted = nullptr);
 
   const nsTArray<nsRect>& GetDestRects() { return mDestRects; }
 
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
   mozilla::Maybe<nsRect> GetClipWithRespectToASR(
       nsDisplayListBuilder* aBuilder,
       const ActiveScrolledRoot* aASR) const override;
 
  private:
   // According to mask property and the capability of aManager, determine
@@ -6343,17 +6344,17 @@ class nsDisplayFilters : public nsDispla
 
   void PaintAsLayer(nsDisplayListBuilder* aBuilder, gfxContext* aCtx,
                     LayerManager* aManager);
 
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
   bool CreateWebRenderCSSFilters(nsTArray<mozilla::wr::WrFilterOp>& wrFilters);
 
  private:
   // relative to mFrame
   nsRect mEffectsBounds;
 };
@@ -6487,17 +6488,17 @@ class nsDisplayTransform : public nsDisp
       const ContainerLayerParameters& aParameters) override;
   already_AddRefed<Layer> BuildLayer(
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aContainerParameters) override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   bool UpdateScrollData(
       mozilla::layers::WebRenderScrollData* aData,
       mozilla::layers::WebRenderLayerScrollData* aLayerData) override;
   bool ShouldBuildLayerEvenIfInvisible(
       nsDisplayListBuilder* aBuilder) const override;
   bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
                          nsRegion* aVisibleRegion) override;
@@ -6854,17 +6855,17 @@ class nsDisplayPerspective : public nsDi
 
   LayerState GetLayerState(
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aParameters) override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
   bool ShouldBuildLayerEvenIfInvisible(
       nsDisplayListBuilder* aBuilder) const override {
     if (!mList.GetChildren()->GetTop()) {
       return false;
     }
     return mList.GetChildren()->GetTop()->ShouldBuildLayerEvenIfInvisible(
@@ -7021,17 +7022,17 @@ class nsDisplaySVGWrapper : public nsDis
   LayerState GetLayerState(
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aParameters) override;
   bool ShouldFlattenAway(nsDisplayListBuilder* aBuilder) override;
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 };
 
 /**
  * A display item for webrender to handle SVG foreign object
  */
 class nsDisplayForeignObject : public nsDisplayWrapList {
  public:
@@ -7049,17 +7050,17 @@ class nsDisplayForeignObject : public ns
       nsDisplayListBuilder* aBuilder, LayerManager* aManager,
       const ContainerLayerParameters& aParameters) override;
   virtual bool ShouldFlattenAway(nsDisplayListBuilder* aBuilder) override;
 
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 };
 
 namespace mozilla {
 
 class PaintTelemetry {
  public:
   enum class Metric {
--- a/layout/painting/nsImageRenderer.cpp
+++ b/layout/painting/nsImageRenderer.cpp
@@ -9,16 +9,17 @@
 #include "nsImageRenderer.h"
 
 #include "mozilla/webrender/WebRenderAPI.h"
 
 #include "gfxContext.h"
 #include "gfxDrawable.h"
 #include "ImageOps.h"
 #include "ImageRegion.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/layers/StackingContextHelper.h"
 #include "mozilla/layers/WebRenderLayerManager.h"
 #include "nsContentUtils.h"
 #include "nsCSSRendering.h"
 #include "nsCSSRenderingGradients.h"
 #include "nsDeviceContext.h"
 #include "nsIFrame.h"
 #include "nsStyleStructInlines.h"
@@ -517,17 +518,17 @@ ImgDrawResult nsImageRenderer::Draw(nsPr
 
   return result;
 }
 
 ImgDrawResult nsImageRenderer::BuildWebRenderDisplayItems(
     nsPresContext* aPresContext, mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const mozilla::layers::StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager, nsDisplayItem* aItem,
+    mozilla::layers::RenderRootStateManager* aManager, nsDisplayItem* aItem,
     const nsRect& aDirtyRect, const nsRect& aDest, const nsRect& aFill,
     const nsPoint& aAnchor, const nsSize& aRepeatSize, const CSSIntRect& aSrc,
     float aOpacity) {
   if (!IsReady()) {
     MOZ_ASSERT_UNREACHABLE(
         "Ensure PrepareImage() has returned true before "
         "calling me");
     return ImgDrawResult::NOT_READY;
@@ -568,17 +569,17 @@ ImgDrawResult nsImageRenderer::BuildWebR
           LayoutDeviceRect::FromAppUnits(aDest, appUnitsPerDevPixel);
       gfx::IntSize decodeSize =
           nsLayoutUtils::ComputeImageContainerDrawingParameters(
               mImageContainer, mForFrame, destRect, aSc, containerFlags,
               svgContext);
 
       RefPtr<layers::ImageContainer> container;
       drawResult = mImageContainer->GetImageContainerAtSize(
-          aManager, decodeSize, svgContext, containerFlags,
+          aManager->LayerManager(), decodeSize, svgContext, containerFlags,
           getter_AddRefs(container));
       if (!container) {
         NS_WARNING("Failed to get image container");
         break;
       }
 
       mozilla::wr::ImageRendering rendering = wr::ToImageRendering(
           nsLayoutUtils::GetSamplingFilterForFrame(aItem->Frame()));
@@ -707,17 +708,17 @@ ImgDrawResult nsImageRenderer::DrawLayer
                  nsPresContext::AppUnitsToIntCSSPixels(mSize.height)),
       aOpacity);
 }
 
 ImgDrawResult nsImageRenderer::BuildWebRenderDisplayItemsForLayer(
     nsPresContext* aPresContext, mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const mozilla::layers::StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager, nsDisplayItem* aItem,
+    mozilla::layers::RenderRootStateManager* aManager, nsDisplayItem* aItem,
     const nsRect& aDest, const nsRect& aFill, const nsPoint& aAnchor,
     const nsRect& aDirty, const nsSize& aRepeatSize, float aOpacity) {
   if (!IsReady()) {
     MOZ_ASSERT_UNREACHABLE(
         "Ensure PrepareImage() has returned true before "
         "calling me");
     return mPrepareResult;
   }
--- a/layout/painting/nsImageRenderer.h
+++ b/layout/painting/nsImageRenderer.h
@@ -12,17 +12,17 @@
 #include "Units.h"
 
 class gfxDrawable;
 namespace mozilla {
 
 namespace layers {
 class StackingContextHelper;
 class WebRenderParentCommand;
-class WebRenderLayerManager;
+class RenderRootStateManager;
 }  // namespace layers
 
 namespace wr {
 class DisplayListBuilder;
 class IpcResourceUpdateQueue;
 }  // namespace wr
 
 // A CSSSizeOrRatio represents a (possibly partially specified) size for use
@@ -195,17 +195,17 @@ class nsImageRenderer {
    * Builds WebRender DisplayItems for an image using
    * {background|mask}-specific arguments.
    * @see nsLayoutUtils::DrawImage() for parameters.
    */
   ImgDrawResult BuildWebRenderDisplayItemsForLayer(
       nsPresContext* aPresContext, mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResource,
       const mozilla::layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager, nsDisplayItem* aItem,
+      mozilla::layers::RenderRootStateManager* aManager, nsDisplayItem* aItem,
       const nsRect& aDest, const nsRect& aFill, const nsPoint& aAnchor,
       const nsRect& aDirty, const nsSize& aRepeatSize, float aOpacity);
 
   /**
    * Draw the image to a single component of a border-image style rendering.
    * aFill The destination rect to be drawn into
    * aSrc is the part of the image to be rendered into a tile (aUnitSize in
    * aFill), if aSrc and the dest tile are different sizes, the image will be
@@ -275,17 +275,17 @@ class nsImageRenderer {
    * currently only used for gradients.
    *
    * @see nsLayoutUtils::DrawImage() for other parameters.
    */
   ImgDrawResult BuildWebRenderDisplayItems(
       nsPresContext* aPresContext, mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const mozilla::layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager, nsDisplayItem* aItem,
+      mozilla::layers::RenderRootStateManager* aManager, nsDisplayItem* aItem,
       const nsRect& aDirtyRect, const nsRect& aDest, const nsRect& aFill,
       const nsPoint& aAnchor, const nsSize& aRepeatSize,
       const mozilla::CSSIntRect& aSrc, float aOpacity = 1.0);
 
   /**
    * Helper method for creating a gfxDrawable from mPaintServerFrame or
    * mImageElementSurface.
    * Requires mType is eStyleImageType_Element.
--- a/layout/tables/nsTableCellFrame.cpp
+++ b/layout/tables/nsTableCellFrame.cpp
@@ -55,17 +55,17 @@ class nsDisplayTableCellSelection final 
         aCtx->GetDrawTarget(), ToReferenceFrame());
   }
   NS_DISPLAY_DECL_NAME("TableCellSelection", TYPE_TABLE_CELL_SELECTION)
 
   bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override {
     RefPtr<nsFrameSelection> frameSelection =
         mFrame->PresShell()->FrameSelection();
     if (frameSelection->GetTableCellSelection()) {
       return false;
     }
 
     return true;
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -46,17 +46,17 @@
 #include "nsDisplayList.h"
 #include "nsIScrollableFrame.h"
 #include "nsCSSProps.h"
 #include "nsStyleChangeList.h"
 #include <algorithm>
 
 #include "gfxPrefs.h"
 #include "mozilla/layers/StackingContextHelper.h"
-#include "mozilla/layers/WebRenderLayerManager.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 
 using namespace mozilla;
 using namespace mozilla::image;
 using namespace mozilla::layout;
 
 using mozilla::gfx::AutoRestoreTransform;
 using mozilla::gfx::DrawTarget;
 using mozilla::gfx::Float;
@@ -1166,17 +1166,18 @@ class nsDisplayTableBorderCollapse final
   virtual ~nsDisplayTableBorderCollapse() {
     MOZ_COUNT_DTOR(nsDisplayTableBorderCollapse);
   }
 #endif
 
   void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
   bool CreateWebRenderCommands(
       wr::DisplayListBuilder& aBuilder, wr::IpcResourceUpdateQueue& aResources,
-      const StackingContextHelper& aSc, layers::WebRenderLayerManager* aManager,
+      const StackingContextHelper& aSc,
+      layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
   NS_DISPLAY_DECL_NAME("TableBorderCollapse", TYPE_TABLE_BORDER_COLLAPSE)
 };
 
 void nsDisplayTableBorderCollapse::Paint(nsDisplayListBuilder* aBuilder,
                                          gfxContext* aCtx) {
   nsPoint pt = ToReferenceFrame();
   DrawTarget* drawTarget = aCtx->GetDrawTarget();
@@ -1192,17 +1193,17 @@ void nsDisplayTableBorderCollapse::Paint
 
   static_cast<nsTableFrame*>(mFrame)->PaintBCBorders(*drawTarget,
                                                      GetPaintRect() - pt);
 }
 
 bool nsDisplayTableBorderCollapse::CreateWebRenderCommands(
     wr::DisplayListBuilder& aBuilder, wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   static_cast<nsTableFrame*>(mFrame)->CreateWebRenderCommandsForBCBorders(
       aBuilder, aSc, GetPaintRect(), ToReferenceFrame());
   return true;
 }
 
 /* static */ void nsTableFrame::GenericTraversal(
     nsDisplayListBuilder* aBuilder, nsFrame* aFrame,
--- a/layout/xul/nsImageBoxFrame.cpp
+++ b/layout/xul/nsImageBoxFrame.cpp
@@ -47,16 +47,17 @@
 
 #include "nsContentUtils.h"
 
 #include "mozilla/BasicEvents.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/Maybe.h"
 #include "SVGImageContext.h"
 #include "Units.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/layers/WebRenderLayerManager.h"
 
 #if defined(XP_WIN)
 // Undefine LoadImage to prevent naming conflict with Windows.
 #undef LoadImage
 #endif
 
 #define ONLOAD_CALLED_TOO_EARLY 1
@@ -370,17 +371,17 @@ ImgDrawResult nsImageBoxFrame::PaintImag
       nsLayoutUtils::GetSamplingFilterForFrame(this), dest, dirty, svgContext,
       aFlags, anchorPoint.ptrOr(nullptr), hasSubRect ? &mSubRect : nullptr);
 }
 
 ImgDrawResult nsImageBoxFrame::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager, nsDisplayItem* aItem,
+    mozilla::layers::RenderRootStateManager* aManager, nsDisplayItem* aItem,
     nsPoint aPt, uint32_t aFlags) {
   ImgDrawResult result;
   Maybe<nsPoint> anchorPoint;
   nsRect dest;
   nsCOMPtr<imgIContainer> imgCon =
       GetImageContainerForPainting(aPt, result, anchorPoint, dest);
   if (!imgCon) {
     return result;
@@ -398,18 +399,18 @@ ImgDrawResult nsImageBoxFrame::CreateWeb
   LayoutDeviceRect fillRect =
       LayoutDeviceRect::FromAppUnits(dest, appUnitsPerDevPixel);
   Maybe<SVGImageContext> svgContext;
   gfx::IntSize decodeSize =
       nsLayoutUtils::ComputeImageContainerDrawingParameters(
           imgCon, aItem->Frame(), fillRect, aSc, containerFlags, svgContext);
 
   RefPtr<layers::ImageContainer> container;
-  result = imgCon->GetImageContainerAtSize(aManager, decodeSize, svgContext,
-                                           containerFlags,
+  result = imgCon->GetImageContainerAtSize(aManager->LayerManager(), decodeSize,
+                                           svgContext, containerFlags,
                                            getter_AddRefs(container));
   if (!container) {
     NS_WARNING("Failed to get image container");
     return result;
   }
 
   mozilla::wr::ImageRendering rendering = wr::ToImageRendering(
       nsLayoutUtils::GetSamplingFilterForFrame(aItem->Frame()));
@@ -489,17 +490,17 @@ void nsDisplayXULImage::Paint(nsDisplayL
 
   nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, result);
 }
 
 bool nsDisplayXULImage::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   nsImageBoxFrame* imageFrame = static_cast<nsImageBoxFrame*>(mFrame);
   if (!imageFrame->CanOptimizeToImageLayer()) {
     return false;
   }
 
   if (!imageFrame->mImageRequest) {
     return true;
--- a/layout/xul/nsImageBoxFrame.h
+++ b/layout/xul/nsImageBoxFrame.h
@@ -92,17 +92,17 @@ class nsImageBoxFrame final : public nsL
   ImgDrawResult PaintImage(gfxContext& aRenderingContext,
                            const nsRect& aDirtyRect, nsPoint aPt,
                            uint32_t aFlags);
 
   ImgDrawResult CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const mozilla::layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager, nsDisplayItem* aItem,
+      mozilla::layers::RenderRootStateManager* aManager, nsDisplayItem* aItem,
       nsPoint aPt, uint32_t aFlags);
 
   bool CanOptimizeToImageLayer();
 
   nsRect GetDestRect(const nsPoint& aOffset, Maybe<nsPoint>& aAnchorPoint);
 
  protected:
   explicit nsImageBoxFrame(ComputedStyle* aStyle);
@@ -165,15 +165,15 @@ class nsDisplayXULImage final : public n
   // Doesn't handle HitTest because nsLeafBoxFrame already creates an
   // event receiver for us
   virtual void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
 
   virtual bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 
   NS_DISPLAY_DECL_NAME("XULImage", TYPE_XUL_IMAGE)
 };
 
 #endif /* nsImageBoxFrame_h___ */
--- a/layout/xul/nsTextBoxFrame.cpp
+++ b/layout/xul/nsTextBoxFrame.cpp
@@ -29,17 +29,17 @@
 #include "nsDisplayList.h"
 #include "nsCSSRendering.h"
 #include "nsIReflowCallback.h"
 #include "nsBoxFrame.h"
 #include "mozilla/Preferences.h"
 #include "nsLayoutUtils.h"
 #include "mozilla/Attributes.h"
 #include "nsUnicodeProperties.h"
-#include "mozilla/layers/WebRenderLayerManager.h"
+#include "mozilla/layers/RenderRootStateManager.h"
 #include "TextDrawTarget.h"
 
 #ifdef ACCESSIBILITY
 #include "nsAccessibilityService.h"
 #endif
 
 #include "nsBidiUtils.h"
 #include "nsBidiPresUtils.h"
@@ -258,17 +258,17 @@ class nsDisplayXULTextBox final : public
 
   void PaintTextToContext(gfxContext* aCtx, nsPoint aOffset,
                           const nscolor* aColor);
 
   virtual bool CreateWebRenderCommands(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager,
+      mozilla::layers::RenderRootStateManager* aManager,
       nsDisplayListBuilder* aDisplayListBuilder) override;
 };
 
 static void PaintTextShadowCallback(gfxContext* aCtx, nsPoint aShadowOffset,
                                     const nscolor& aShadowColor, void* aData) {
   reinterpret_cast<nsDisplayXULTextBox*>(aData)->PaintTextToContext(
       aCtx, aShadowOffset, &aShadowColor);
 }
@@ -293,17 +293,17 @@ void nsDisplayXULTextBox::PaintTextToCon
   static_cast<nsTextBoxFrame*>(mFrame)->PaintTitle(
       *aCtx, GetPaintRect(), ToReferenceFrame() + aOffset, aColor);
 }
 
 bool nsDisplayXULTextBox::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager,
+    mozilla::layers::RenderRootStateManager* aManager,
     nsDisplayListBuilder* aDisplayListBuilder) {
   bool snap = false;
   auto bounds = GetBounds(aDisplayListBuilder, &snap);
 
   if (bounds.IsEmpty()) {
     return true;
   }
 
--- a/widget/cocoa/nsNativeThemeCocoa.h
+++ b/widget/cocoa/nsNativeThemeCocoa.h
@@ -391,17 +391,17 @@ class nsNativeThemeCocoa : private nsNat
 
   // The nsITheme interface.
   NS_IMETHOD DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
                                   StyleAppearance aAppearance, const nsRect& aRect,
                                   const nsRect& aDirtyRect) override;
   bool CreateWebRenderCommandsForWidget(mozilla::wr::DisplayListBuilder& aBuilder,
                                         mozilla::wr::IpcResourceUpdateQueue& aResources,
                                         const mozilla::layers::StackingContextHelper& aSc,
-                                        mozilla::layers::WebRenderLayerManager* aManager,
+                                        mozilla::layers::RenderRootStateManager* aManager,
                                         nsIFrame* aFrame, StyleAppearance aAppearance,
                                         const nsRect& aRect) override;
   MOZ_MUST_USE LayoutDeviceIntMargin GetWidgetBorder(nsDeviceContext* aContext, nsIFrame* aFrame,
                                                      StyleAppearance aAppearance) override;
 
   bool GetWidgetPadding(nsDeviceContext* aContext, nsIFrame* aFrame, StyleAppearance aAppearance,
                         LayoutDeviceIntMargin* aResult) override;
 
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -3805,17 +3805,17 @@ nsNativeThemeCocoa::RenderWidget(const W
 
   nativeDrawing.EndNativeDrawing();
 }
 
 bool
 nsNativeThemeCocoa::CreateWebRenderCommandsForWidget(mozilla::wr::DisplayListBuilder& aBuilder,
                                                      mozilla::wr::IpcResourceUpdateQueue& aResources,
                                                      const mozilla::layers::StackingContextHelper& aSc,
-                                                     mozilla::layers::WebRenderLayerManager* aManager,
+                                                     mozilla::layers::RenderRootStateManager* aManager,
                                                      nsIFrame* aFrame,
                                                      StyleAppearance aAppearance,
                                                      const nsRect& aRect)
 {
   nsPresContext* presContext = aFrame->PresContext();
   wr::LayoutRect bounds = wr::ToRoundedLayoutRect(
     LayoutDeviceRect::FromAppUnits(aRect, presContext->AppUnitsPerDevPixel()));
 
--- a/widget/gtk/nsNativeThemeGTK.cpp
+++ b/widget/gtk/nsNativeThemeGTK.cpp
@@ -1221,17 +1221,17 @@ nsNativeThemeGTK::DrawWidgetBackground(g
 
   return NS_OK;
 }
 
 bool nsNativeThemeGTK::CreateWebRenderCommandsForWidget(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
     const mozilla::layers::StackingContextHelper& aSc,
-    mozilla::layers::WebRenderLayerManager* aManager, nsIFrame* aFrame,
+    mozilla::layers::RenderRootStateManager* aManager, nsIFrame* aFrame,
     StyleAppearance aAppearance, const nsRect& aRect) {
   nsPresContext* presContext = aFrame->PresContext();
   wr::LayoutRect bounds =
       wr::ToRoundedLayoutRect(LayoutDeviceRect::FromAppUnits(
           aRect, presContext->AppUnitsPerDevPixel()));
 
   switch (aAppearance) {
     case StyleAppearance::Window:
--- a/widget/gtk/nsNativeThemeGTK.h
+++ b/widget/gtk/nsNativeThemeGTK.h
@@ -29,17 +29,17 @@ class nsNativeThemeGTK final : private n
                                   StyleAppearance aAppearance,
                                   const nsRect& aRect,
                                   const nsRect& aDirtyRect) override;
 
   bool CreateWebRenderCommandsForWidget(
       mozilla::wr::DisplayListBuilder& aBuilder,
       mozilla::wr::IpcResourceUpdateQueue& aResources,
       const mozilla::layers::StackingContextHelper& aSc,
-      mozilla::layers::WebRenderLayerManager* aManager, nsIFrame* aFrame,
+      mozilla::layers::RenderRootStateManager* aManager, nsIFrame* aFrame,
       StyleAppearance aAppearance, const nsRect& aRect) override;
 
   MOZ_MUST_USE LayoutDeviceIntMargin
   GetWidgetBorder(nsDeviceContext* aContext, nsIFrame* aFrame,
                   StyleAppearance aAppearance) override;
 
   bool GetWidgetPadding(nsDeviceContext* aContext, nsIFrame* aFrame,
                         StyleAppearance aAppearance,