Merge inbound to central, a=merge CLOSED TREE
authorWes Kocher <wkocher@mozilla.com>
Wed, 19 Jul 2017 17:29:56 -0700
changeset 418466 eb1d92b2b6a4161492561250f51bae5bafeda68a
parent 418398 a8885191775ad1f655d2826f8f8e943a9a985f43 (current diff)
parent 418465 6fe44a6c4e46426eebee98c121800c0263a06b47 (diff)
child 418467 4a7dd87506167cf613c905f0249cceb70c7a6b7c
child 418514 541d60bea382d84d29795311d2f8b5b98c84e11c
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge
milestone56.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
Merge inbound to central, a=merge CLOSED TREE MozReview-Commit-ID: CBL7SUEUGKV
gfx/layers/apz/src/APZCTreeManager.cpp
js/xpconnect/tests/mochitest/file_crossOriginObjects.html
js/xpconnect/tests/mochitest/file_crossOriginObjects_documentDomain.html
js/xpconnect/tests/mochitest/test_crossOriginObjects.html
--- a/accessible/ipc/DocAccessibleParent.cpp
+++ b/accessible/ipc/DocAccessibleParent.cpp
@@ -669,17 +669,23 @@ DocAccessibleParent::SendParentCOMProxy(
   }
 
   IAccessible* rawNative = nullptr;
   outerDoc->GetNativeInterface((void**) &rawNative);
   MOZ_ASSERT(rawNative);
 
   IAccessibleHolder::COMPtrType ptr(rawNative);
   IAccessibleHolder holder(Move(ptr));
-  Unused << PDocAccessibleParent::SendParentCOMProxy(holder);
+  if (!PDocAccessibleParent::SendParentCOMProxy(holder)) {
+    return;
+  }
+
+#if defined(MOZ_CONTENT_SANDBOX)
+  mParentProxyStream = Move(holder.GetPreservedStream());
+#endif // defined(MOZ_CONTENT_SANDBOX)
 }
 
 void
 DocAccessibleParent::SetEmulatedWindowHandle(HWND aWindowHandle)
 {
   if (!aWindowHandle && mEmulatedWindowHandle && IsTopLevel()) {
     ::DestroyWindow(mEmulatedWindowHandle);
   }
--- a/accessible/ipc/DocAccessibleParent.h
+++ b/accessible/ipc/DocAccessibleParent.h
@@ -231,17 +231,21 @@ private:
   xpcAccessibleGeneric* GetXPCAccessible(ProxyAccessible* aProxy);
 
   nsTArray<uint64_t> mChildDocs;
   uint64_t mParentDoc;
 
 #if defined(XP_WIN)
   // The handle associated with the emulated window that contains this document
   HWND mEmulatedWindowHandle;
-#endif
+
+#if defined(MOZ_CONTENT_SANDBOX)
+  mscom::PreservedStreamPtr mParentProxyStream;
+#endif // defined(MOZ_CONTENT_SANDBOX)
+#endif // defined(XP_WIN)
 
   /*
    * Conceptually this is a map from IDs to proxies, but we store the ID in the
    * proxy object so we can't use a real map.
    */
   nsTHashtable<ProxyEntry> mAccessibles;
   uint64_t mActorID;
   bool mTopLevel;
--- a/browser/base/content/test/tabs/browser.ini
+++ b/browser/base/content/test/tabs/browser.ini
@@ -8,15 +8,17 @@ support-files =
 [browser_contextmenu_openlink_after_tabnavigated.js]
 [browser_isLocalAboutURI.js]
 [browser_tabCloseProbes.js]
 [browser_tabSpinnerProbe.js]
 skip-if = !e10s # Tab spinner is e10s only.
 [browser_tabSwitchPrintPreview.js]
 skip-if = os == 'mac'
 [browser_navigatePinnedTab.js]
+[browser_new_file_whitelisted_http_tab.js]
+skip-if = !e10s # Test only relevant for e10s.
 [browser_new_web_tab_in_file_process_pref.js]
 skip-if = !e10s # Pref and test only relevant for e10s.
 [browser_opened_file_tab_navigated_to_web.js]
 [browser_reload_deleted_file.js]
 [browser_tabswitch_updatecommands.js]
 [browser_viewsource_of_data_URI_in_file_process.js]
 [browser_open_newtab_start_observer_notification.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabs/browser_new_file_whitelisted_http_tab.js
@@ -0,0 +1,27 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+
+const TEST_HTTP = "http://example.org/";
+
+// Test for bug 1378377.
+add_task(async function() {
+  // Set prefs to ensure file content process.
+  await SpecialPowers.pushPrefEnv(
+    {set: [["browser.tabs.remote.separateFileUriProcess", true]]});
+
+  await BrowserTestUtils.withNewTab(TEST_HTTP, async function(fileBrowser) {
+    is(fileBrowser.remoteType, E10SUtils.WEB_REMOTE_TYPE,
+      "Check that tab normally has web remote type.");
+  });
+
+  // Set prefs to whitelist TEST_HTTP for file:// URI use.
+  await SpecialPowers.pushPrefEnv(
+    {set: [["capability.policy.policynames", "allowFileURI"],
+           ["capability.policy.allowFileURI.sites", TEST_HTTP],
+           ["capability.policy.allowFileURI.checkloaduri.enabled", "allAccess"]]});
+
+  await BrowserTestUtils.withNewTab(TEST_HTTP, async function(fileBrowser) {
+    is(fileBrowser.remoteType, E10SUtils.FILE_REMOTE_TYPE,
+      "Check that tab now has file remote type.");
+  });
+});
--- a/browser/modules/E10SUtils.jsm
+++ b/browser/modules/E10SUtils.jsm
@@ -42,30 +42,36 @@ const WEB_REMOTE_TYPE = "web";
 const FILE_REMOTE_TYPE = "file";
 const EXTENSION_REMOTE_TYPE = "extension";
 
 // This must start with the WEB_REMOTE_TYPE above.
 const LARGE_ALLOCATION_REMOTE_TYPE = "webLargeAllocation";
 const DEFAULT_REMOTE_TYPE = WEB_REMOTE_TYPE;
 
 function validatedWebRemoteType(aPreferredRemoteType, aTargetUri, aCurrentUri) {
+  // If the domain is whitelisted to allow it to use file:// URIs, then we have
+  // to run it in a file content process, in case it uses file:// sub-resources.
+  const sm = Services.scriptSecurityManager;
+  if (sm.inFileURIWhitelist(aTargetUri)) {
+    return FILE_REMOTE_TYPE;
+  }
+
   if (!aPreferredRemoteType) {
     return WEB_REMOTE_TYPE;
   }
 
   if (aPreferredRemoteType.startsWith(WEB_REMOTE_TYPE)) {
     return aPreferredRemoteType;
   }
 
   if (allowLinkedWebInFileUriProcess &&
       aPreferredRemoteType == FILE_REMOTE_TYPE) {
     // If aCurrentUri is passed then we should only allow FILE_REMOTE_TYPE
     // when it is same origin as target.
     if (aCurrentUri) {
-      const sm = Services.scriptSecurityManager;
       try {
         // checkSameOriginURI throws when not same origin.
         sm.checkSameOriginURI(aCurrentUri, aTargetUri, false);
         return FILE_REMOTE_TYPE;
       } catch (e) {
         return WEB_REMOTE_TYPE;
       }
     }
--- a/caps/nsIScriptSecurityManager.idl
+++ b/caps/nsIScriptSecurityManager.idl
@@ -121,16 +121,23 @@ interface nsIScriptSecurityManager : nsI
      * hence will check whether fixed-up versions of the URI are allowed to
      * load as well); if any of the versions of this URI is not allowed, this
      * function will return error code NS_ERROR_DOM_BAD_URI.
      */
     void checkLoadURIStrWithPrincipal(in nsIPrincipal aPrincipal,
                                       in AUTF8String uri,
                                       in unsigned long flags);
 
+    /**
+     * Returns true if the URI is from a domain that is white-listed through
+     * prefs to be allowed to use file:// URIs.
+     * @param aUri the URI to be tested
+     */
+    bool inFileURIWhitelist(in nsIURI aUri);
+
     ///////////////// Principals ///////////////////////
 
     /**
      * Return the all-powerful system principal.
      */
     nsIPrincipal getSystemPrincipal();
 
     /**
--- a/caps/nsScriptSecurityManager.cpp
+++ b/caps/nsScriptSecurityManager.cpp
@@ -936,20 +936,20 @@ nsScriptSecurityManager::CheckLoadURIFla
     // Check for target URI pointing to a file
     rv = NS_URIChainHasFlags(aTargetURI,
                              nsIProtocolHandler::URI_IS_LOCAL_FILE,
                              &hasFlags);
     NS_ENSURE_SUCCESS(rv, rv);
     if (hasFlags) {
         // Allow domains that were whitelisted in the prefs. In 99.9% of cases,
         // this array is empty.
-        for (nsIURI* uri : EnsureFileURIWhitelist()) {
-            if (EqualOrSubdomain(aSourceURI, uri)) {
-                return NS_OK;
-            }
+        bool isWhitelisted;
+        MOZ_ALWAYS_SUCCEEDS(InFileURIWhitelist(aSourceURI, &isWhitelisted));
+        if (isWhitelisted) {
+            return NS_OK;
         }
 
         // Allow chrome://
         bool isChrome = false;
         if (NS_SUCCEEDED(aSourceBaseURI->SchemeIs("chrome", &isChrome)) && isChrome) {
             return NS_OK;
         }
 
@@ -1091,16 +1091,33 @@ nsScriptSecurityManager::CheckLoadURIStr
             return rv;
         }
         NS_ENSURE_SUCCESS(rv, rv);
     }
 
     return rv;
 }
 
+NS_IMETHODIMP
+nsScriptSecurityManager::InFileURIWhitelist(nsIURI* aUri, bool* aResult)
+{
+    MOZ_ASSERT(aUri);
+    MOZ_ASSERT(aResult);
+
+    *aResult = false;
+    for (nsIURI* uri : EnsureFileURIWhitelist()) {
+        if (EqualOrSubdomain(aUri, uri)) {
+            *aResult = true;
+            return NS_OK;
+        }
+    }
+
+    return NS_OK;
+}
+
 ///////////////// Principals ///////////////////////
 
 NS_IMETHODIMP
 nsScriptSecurityManager::GetSystemPrincipal(nsIPrincipal **result)
 {
     NS_ADDREF(*result = mSystemPrincipal);
 
     return NS_OK;
--- a/devtools/client/shared/components/notification-box.css
+++ b/devtools/client/shared/components/notification-box.css
@@ -28,20 +28,20 @@
 .notificationbox .details:dir(rtl)
 .notificationbox .notificationInner:dir(rtl) {
   flex-direction: row-reverse;
 }
 
 /* Style */
 
 .notificationbox .notification {
-  background-color: InfoBackground;
+  color: var(--theme-body-color-alt);
+  background-color: var(--theme-body-background);
   text-shadow: none;
-  border-top: 1px solid ThreeDShadow;
-  border-bottom: 1px solid ThreeDShadow;
+  border-bottom: 1px solid var(--theme-splitter-color);
 }
 
 .notificationbox .notification[data-type="info"] {
   color: -moz-DialogText;
   background-color: -moz-Dialog;
 }
 
 .notificationbox .notification[data-type="critical"] {
--- a/dom/base/CustomElementRegistry.cpp
+++ b/dom/base/CustomElementRegistry.cpp
@@ -50,16 +50,20 @@ CustomElementCallback::Call()
     case nsIDocument::eDetached:
       static_cast<LifecycleDetachedCallback *>(mCallback.get())->Call(mThisObject, rv);
       break;
     case nsIDocument::eAttributeChanged:
       static_cast<LifecycleAttributeChangedCallback *>(mCallback.get())->Call(mThisObject,
         mArgs.name, mArgs.oldValue, mArgs.newValue, rv);
       break;
   }
+
+  // If callbacks throw exceptions, it'll be handled and reported in
+  // Lifecycle*Callback::Call function.
+  rv.SuppressException();
 }
 
 void
 CustomElementCallback::Traverse(nsCycleCollectionTraversalCallback& aCb) const
 {
   NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "mThisObject");
   aCb.NoteXPCOMChild(mThisObject);
 
@@ -83,53 +87,39 @@ CustomElementCallback::CustomElementCall
 
 CustomElementData::CustomElementData(nsIAtom* aType)
   : CustomElementData(aType, CustomElementData::State::eUndefined)
 {
 }
 
 CustomElementData::CustomElementData(nsIAtom* aType, State aState)
   : mType(aType)
-  , mCurrentCallback(-1)
   , mElementIsBeingCreated(false)
   , mCreatedCallbackInvoked(true)
-  , mAssociatedMicroTask(-1)
   , mState(aState)
 {
 }
 
-void
-CustomElementData::RunCallbackQueue()
-{
-  // Note: It's possible to re-enter this method.
-  while (static_cast<uint32_t>(++mCurrentCallback) < mCallbackQueue.Length()) {
-    mCallbackQueue[mCurrentCallback]->Call();
-  }
-
-  mCallbackQueue.Clear();
-  mCurrentCallback = -1;
-}
-
 //-----------------------------------------------------
 // CustomElementRegistry
 
 // Only needed for refcounted objects.
 NS_IMPL_CYCLE_COLLECTION_CLASS(CustomElementRegistry)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CustomElementRegistry)
   tmp->mCustomDefinitions.Clear();
   tmp->mConstructors.clear();
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mWhenDefinedPromiseMap)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(CustomElementRegistry)
   for (auto iter = tmp->mCustomDefinitions.Iter(); !iter.Done(); iter.Next()) {
-    nsAutoPtr<LifecycleCallbacks>& callbacks = iter.UserData()->mCallbacks;
+    auto& callbacks = iter.UserData()->mCallbacks;
 
     if (callbacks->mAttributeChangedCallback.WasPassed()) {
       NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb,
         "mCustomDefinitions->mCallbacks->mAttributeChangedCallback");
       cb.NoteXPCOMChild(callbacks->mAttributeChangedCallback.Value());
     }
 
     if (callbacks->mCreatedCallback.WasPassed()) {
@@ -183,68 +173,25 @@ NS_INTERFACE_MAP_END
 
 /* static */ bool
 CustomElementRegistry::IsCustomElementEnabled(JSContext* aCx, JSObject* aObject)
 {
   return nsContentUtils::IsCustomElementsEnabled() ||
          nsContentUtils::IsWebComponentsEnabled();
 }
 
-/* static */ void
-CustomElementRegistry::ProcessTopElementQueue()
-{
-  MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
-
-  nsTArray<RefPtr<CustomElementData>>& stack = *sProcessingStack;
-  uint32_t firstQueue = stack.LastIndexOf((CustomElementData*) nullptr);
-
-  for (uint32_t i = firstQueue + 1; i < stack.Length(); ++i) {
-    // Callback queue may have already been processed in an earlier
-    // element queue or in an element queue that was popped
-    // off more recently.
-    if (stack[i]->mAssociatedMicroTask != -1) {
-      stack[i]->RunCallbackQueue();
-      stack[i]->mAssociatedMicroTask = -1;
-    }
-  }
-
-  // If this was actually the base element queue, don't bother trying to pop
-  // the first "queue" marker (sentinel).
-  if (firstQueue != 0) {
-    stack.SetLength(firstQueue);
-  } else {
-    // Don't pop sentinel for base element queue.
-    stack.SetLength(1);
-  }
-}
-
-/* static */ void
-CustomElementRegistry::XPCOMShutdown()
-{
-  sProcessingStack.reset();
-}
-
-/* static */ Maybe<nsTArray<RefPtr<CustomElementData>>>
-CustomElementRegistry::sProcessingStack;
-
 CustomElementRegistry::CustomElementRegistry(nsPIDOMWindowInner* aWindow)
  : mWindow(aWindow)
  , mIsCustomDefinitionRunning(false)
 {
   MOZ_ASSERT(aWindow);
   MOZ_ASSERT(aWindow->IsInnerWindow());
   MOZ_ALWAYS_TRUE(mConstructors.init());
 
   mozilla::HoldJSObjects(this);
-
-  if (!sProcessingStack) {
-    sProcessingStack.emplace();
-    // Add the base queue sentinel to the processing stack.
-    sProcessingStack->AppendElement((CustomElementData*) nullptr);
-  }
 }
 
 CustomElementRegistry::~CustomElementRegistry()
 {
   mozilla::DropJSObjects(this);
 }
 
 CustomElementDefinition*
@@ -338,24 +285,25 @@ CustomElementRegistry::SetupCustomElemen
     // The element doesn't match the local name for the
     // definition, thus the element isn't a custom element
     // and we don't need to do anything more.
     return;
   }
 
   // Enqueuing the created callback will set the CustomElementData on the
   // element, causing prototype swizzling to occur in Element::WrapObject.
-  EnqueueLifecycleCallback(nsIDocument::eCreated, aElement, nullptr, definition);
+  // We make it synchronously for createElement/createElementNS in order to
+  // pass tests. It'll be removed when we deprecate custom elements v0.
+  SyncInvokeReactions(nsIDocument::eCreated, aElement, definition);
 }
 
-void
-CustomElementRegistry::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType,
-                                                Element* aCustomElement,
-                                                LifecycleCallbackArgs* aArgs,
-                                                CustomElementDefinition* aDefinition)
+UniquePtr<CustomElementCallback>
+CustomElementRegistry::CreateCustomElementCallback(
+  nsIDocument::ElementCallbackType aType, Element* aCustomElement,
+  LifecycleCallbackArgs* aArgs, CustomElementDefinition* aDefinition)
 {
   RefPtr<CustomElementData> elementData = aCustomElement->GetCustomElementData();
   MOZ_ASSERT(elementData, "CustomElementData should exist");
 
   // Let DEFINITION be ELEMENT's definition
   CustomElementDefinition* definition = aDefinition;
   if (!definition) {
     mozilla::dom::NodeInfo* info = aCustomElement->NodeInfo();
@@ -364,17 +312,17 @@ CustomElementRegistry::EnqueueLifecycleC
     // is a extended custom element e.g. <button is="x-button">.
     nsCOMPtr<nsIAtom> typeAtom = elementData ?
       elementData->mType.get() : info->NameAtom();
 
     definition = mCustomDefinitions.Get(typeAtom);
     if (!definition || definition->mLocalName != info->NameAtom()) {
       // Trying to enqueue a callback for an element that is not
       // a custom element. We are done, nothing to do.
-      return;
+      return nullptr;
     }
   }
 
   // Let CALLBACK be the callback associated with the key NAME in CALLBACKS.
   CallbackFunction* func = nullptr;
   switch (aType) {
     case nsIDocument::eCreated:
       if (definition->mCallbacks->mCreatedCallback.WasPassed()) {
@@ -398,73 +346,80 @@ CustomElementRegistry::EnqueueLifecycleC
       if (definition->mCallbacks->mAttributeChangedCallback.WasPassed()) {
         func = definition->mCallbacks->mAttributeChangedCallback.Value();
       }
       break;
   }
 
   // If there is no such callback, stop.
   if (!func) {
-    return;
+    return nullptr;
   }
 
   if (aType == nsIDocument::eCreated) {
     elementData->mCreatedCallbackInvoked = false;
   } else if (!elementData->mCreatedCallbackInvoked) {
     // Callbacks other than created callback must not be enqueued
     // until after the created callback has been invoked.
-    return;
+    return nullptr;
   }
 
   // Add CALLBACK to ELEMENT's callback queue.
-  CustomElementCallback* callback = new CustomElementCallback(aCustomElement,
-                                                              aType,
-                                                              func,
-                                                              elementData);
-  // Ownership of callback is taken by mCallbackQueue.
-  elementData->mCallbackQueue.AppendElement(callback);
+  auto callback =
+    MakeUnique<CustomElementCallback>(aCustomElement, aType, func, elementData);
+
   if (aArgs) {
     callback->SetArgs(*aArgs);
   }
 
-  if (!elementData->mElementIsBeingCreated) {
-    CustomElementData* lastData =
-      sProcessingStack->SafeLastElement(nullptr);
+  return Move(callback);
+}
 
-    // A new element queue needs to be pushed if the queue at the
-    // top of the stack is associated with another microtask level.
-    bool shouldPushElementQueue =
-      (!lastData || lastData->mAssociatedMicroTask <
-         static_cast<int32_t>(nsContentUtils::MicroTaskLevel()));
+void
+CustomElementRegistry::SyncInvokeReactions(nsIDocument::ElementCallbackType aType,
+                                           Element* aCustomElement,
+                                           CustomElementDefinition* aDefinition)
+{
+  auto callback = CreateCustomElementCallback(aType, aCustomElement, nullptr,
+                                              aDefinition);
+  if (!callback) {
+    return;
+  }
 
-    // Push a new element queue onto the processing stack when appropriate
-    // (when we enter a new microtask).
-    if (shouldPushElementQueue) {
-      // Push a sentinel value on the processing stack to mark the
-      // boundary between the element queues.
-      sProcessingStack->AppendElement((CustomElementData*) nullptr);
-    }
+  UniquePtr<CustomElementReaction> reaction(Move(
+    MakeUnique<CustomElementCallbackReaction>(this, aDefinition,
+                                              Move(callback))));
+
+  RefPtr<SyncInvokeReactionRunnable> runnable =
+    new SyncInvokeReactionRunnable(Move(reaction), aCustomElement);
 
-    sProcessingStack->AppendElement(elementData);
-    elementData->mAssociatedMicroTask =
-      static_cast<int32_t>(nsContentUtils::MicroTaskLevel());
+  nsContentUtils::AddScriptRunner(runnable);
+}
 
-    // Add a script runner to pop and process the element queue at
-    // the top of the processing stack.
-    if (shouldPushElementQueue) {
-      // Lifecycle callbacks enqueued by user agent implementation
-      // should be invoked prior to returning control back to script.
-      // Create a script runner to process the top of the processing
-      // stack as soon as it is safe to run script.
-      nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction(
-        "dom::CustomElementRegistry::EnqueueLifecycleCallback",
-        &CustomElementRegistry::ProcessTopElementQueue);
-      nsContentUtils::AddScriptRunner(runnable);
-    }
+void
+CustomElementRegistry::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType,
+                                                Element* aCustomElement,
+                                                LifecycleCallbackArgs* aArgs,
+                                                CustomElementDefinition* aDefinition)
+{
+  auto callback =
+    CreateCustomElementCallback(aType, aCustomElement, aArgs, aDefinition);
+  if (!callback) {
+    return;
   }
+
+  DocGroup* docGroup = mWindow->GetDocGroup();
+  if (!docGroup) {
+    return;
+  }
+
+  CustomElementReactionsStack* reactionsStack =
+    docGroup->CustomElementReactionsStack();
+  reactionsStack->EnqueueCallbackReaction(this, aCustomElement, aDefinition,
+                                          Move(callback));
 }
 
 void
 CustomElementRegistry::GetCustomPrototype(nsIAtom* aAtom,
                                           JS::MutableHandle<JSObject*> aPrototype)
 {
   mozilla::dom::CustomElementDefinition* definition = mCustomDefinitions.Get(aAtom);
   if (definition) {
@@ -939,16 +894,26 @@ void
 CustomElementReactionsStack::EnqueueUpgradeReaction(CustomElementRegistry* aRegistry,
                                                     Element* aElement,
                                                     CustomElementDefinition* aDefinition)
 {
   Enqueue(aElement, new CustomElementUpgradeReaction(aRegistry, aDefinition));
 }
 
 void
+CustomElementReactionsStack::EnqueueCallbackReaction(CustomElementRegistry* aRegistry,
+                                                     Element* aElement,
+                                                     CustomElementDefinition* aDefinition,
+                                                     UniquePtr<CustomElementCallback> aCustomElementCallback)
+{
+  Enqueue(aElement, new CustomElementCallbackReaction(aRegistry, aDefinition,
+                                                      Move(aCustomElementCallback)));
+}
+
+void
 CustomElementReactionsStack::Enqueue(Element* aElement,
                                      CustomElementReaction* aReaction)
 {
   RefPtr<CustomElementData> elementData = aElement->GetCustomElementData();
   MOZ_ASSERT(elementData, "CustomElementData should exist");
 
   // Add element to the current element queue.
   if (!mReactionsStack.IsEmpty()) {
@@ -979,30 +944,35 @@ CustomElementReactionsStack::InvokeBacku
   if (!mBackupQueue.IsEmpty()) {
     InvokeReactions(mBackupQueue);
   }
 }
 
 void
 CustomElementReactionsStack::InvokeReactions(ElementQueue& aElementQueue)
 {
+  // Note: It's possible to re-enter this method.
   for (uint32_t i = 0; i < aElementQueue.Length(); ++i) {
     nsCOMPtr<Element> element = do_QueryReferent(aElementQueue[i]);
 
     if (!element) {
       continue;
     }
 
     RefPtr<CustomElementData> elementData = element->GetCustomElementData();
     MOZ_ASSERT(elementData, "CustomElementData should exist");
 
-    nsTArray<nsAutoPtr<CustomElementReaction>>& reactions =
-      elementData->mReactionQueue;
+    auto& reactions = elementData->mReactionQueue;
     for (uint32_t j = 0; j < reactions.Length(); ++j) {
-      reactions.ElementAt(j)->Invoke(element);
+      // Transfer the ownership of the entry due to reentrant invocation of
+      // this funciton. The entry will be removed when bug 1379573 is landed.
+      auto reaction(Move(reactions.ElementAt(j)));
+      if (reaction) {
+        reaction->Invoke(element);
+      }
     }
     reactions.Clear();
   }
   aElementQueue.Clear();
 }
 
 //-----------------------------------------------------
 // CustomElementDefinition
@@ -1027,10 +997,19 @@ CustomElementDefinition::CustomElementDe
 // CustomElementUpgradeReaction
 
 /* virtual */ void
 CustomElementUpgradeReaction::Invoke(Element* aElement)
 {
   mRegistry->Upgrade(aElement, mDefinition);
 }
 
+//-----------------------------------------------------
+// CustomElementCallbackReaction
+
+/* virtual */ void
+CustomElementCallbackReaction::Invoke(Element* aElement)
+{
+  mCustomElementCallback->Call();
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/base/CustomElementRegistry.h
+++ b/dom/base/CustomElementRegistry.h
@@ -80,45 +80,33 @@ struct CustomElementData
   enum class State {
     eUndefined,
     eFailed,
     eCustom
   };
 
   explicit CustomElementData(nsIAtom* aType);
   CustomElementData(nsIAtom* aType, State aState);
-  // Objects in this array are transient and empty after each microtask
-  // checkpoint.
-  nsTArray<nsAutoPtr<CustomElementCallback>> mCallbackQueue;
   // Custom element type, for <button is="x-button"> or <x-button>
   // this would be x-button.
   nsCOMPtr<nsIAtom> mType;
-  // The callback that is next to be processed upon calling RunCallbackQueue.
-  int32_t mCurrentCallback;
   // Element is being created flag as described in the custom elements spec.
   bool mElementIsBeingCreated;
   // Flag to determine if the created callback has been invoked, thus it
   // determines if other callbacks can be enqueued.
   bool mCreatedCallbackInvoked;
-  // The microtask level associated with the callbacks in the callback queue,
-  // it is used to determine if a new queue needs to be pushed onto the
-  // processing stack.
-  int32_t mAssociatedMicroTask;
   // Custom element state as described in the custom element spec.
   State mState;
   // custom element reaction queue as described in the custom element spec.
   // There is 1 reaction in reaction queue, when 1) it becomes disconnected,
   // 2) it’s adopted into a new document, 3) its attributes are changed,
   // appended, removed, or replaced.
   // There are 3 reactions in reaction queue when doing upgrade operation,
   // e.g., create an element, insert a node.
-  AutoTArray<nsAutoPtr<CustomElementReaction>, 3> mReactionQueue;
-
-  // Empties the callback queue.
-  void RunCallbackQueue();
+  AutoTArray<UniquePtr<CustomElementReaction>, 3> mReactionQueue;
 
 private:
   virtual ~CustomElementData() {}
 };
 
 // The required information for a custom element as defined in:
 // https://html.spec.whatwg.org/multipage/scripting.html#custom-element-definition
 struct CustomElementDefinition
@@ -138,17 +126,17 @@ struct CustomElementDefinition
 
   // The custom element constructor.
   JS::Heap<JSObject *> mConstructor;
 
   // The prototype to use for new custom elements of this type.
   JS::Heap<JSObject *> mPrototype;
 
   // The lifecycle callbacks to call for this custom element.
-  nsAutoPtr<mozilla::dom::LifecycleCallbacks> mCallbacks;
+  UniquePtr<mozilla::dom::LifecycleCallbacks> mCallbacks;
 
   // A construction stack.
   // TODO: Bug 1287348 - Implement construction stack for upgrading an element
 
   // The document custom element order.
   uint32_t mDocOrder;
 
   bool IsCustomBuiltIn() {
@@ -159,20 +147,23 @@ struct CustomElementDefinition
 class CustomElementReaction
 {
 public:
   explicit CustomElementReaction(CustomElementRegistry* aRegistry,
                                  CustomElementDefinition* aDefinition)
     : mRegistry(aRegistry)
     , mDefinition(aDefinition)
   {
-  };
+  }
 
   virtual ~CustomElementReaction() = default;
   virtual void Invoke(Element* aElement) = 0;
+  virtual void Traverse(nsCycleCollectionTraversalCallback& aCb) const
+  {
+  }
 
 protected:
   CustomElementRegistry* mRegistry;
   CustomElementDefinition* mDefinition;
 };
 
 class CustomElementUpgradeReaction final : public CustomElementReaction
 {
@@ -182,16 +173,37 @@ public:
     : CustomElementReaction(aRegistry, aDefinition)
   {
   }
 
 private:
    virtual void Invoke(Element* aElement) override;
 };
 
+class CustomElementCallbackReaction final : public CustomElementReaction
+{
+  public:
+    CustomElementCallbackReaction(CustomElementRegistry* aRegistry,
+                                  CustomElementDefinition* aDefinition,
+                                  UniquePtr<CustomElementCallback> aCustomElementCallback)
+      : CustomElementReaction(aRegistry, aDefinition)
+      , mCustomElementCallback(Move(aCustomElementCallback))
+    {
+    }
+
+    virtual void Traverse(nsCycleCollectionTraversalCallback& aCb) const override
+    {
+      mCustomElementCallback->Traverse(aCb);
+    }
+
+  private:
+    virtual void Invoke(Element* aElement) override;
+    UniquePtr<CustomElementCallback> mCustomElementCallback;
+};
+
 // https://html.spec.whatwg.org/multipage/scripting.html#custom-element-reactions-stack
 class CustomElementReactionsStack
 {
 public:
   NS_INLINE_DECL_REFCOUNTING(CustomElementReactionsStack)
 
   CustomElementReactionsStack()
     : mIsBackupQueueProcessing(false)
@@ -207,16 +219,25 @@ public:
   /**
    * Enqueue a custom element upgrade reaction
    * https://html.spec.whatwg.org/multipage/scripting.html#enqueue-a-custom-element-upgrade-reaction
    */
   void EnqueueUpgradeReaction(CustomElementRegistry* aRegistry,
                               Element* aElement,
                               CustomElementDefinition* aDefinition);
 
+  /**
+   * Enqueue a custom element callback reaction
+   * https://html.spec.whatwg.org/multipage/scripting.html#enqueue-a-custom-element-callback-reaction
+   */
+  void EnqueueCallbackReaction(CustomElementRegistry* aRegistry,
+                               Element* aElement,
+                               CustomElementDefinition* aDefinition,
+                               UniquePtr<CustomElementCallback> aCustomElementCallback);
+
   // [CEReactions] Before executing the algorithm's steps
   // Push a new element queue onto the custom element reactions stack.
   void CreateAndPushElementQueue();
 
   // [CEReactions] After executing the algorithm's steps
   // Pop the element queue from the custom element reactions stack,
   // and invoke custom element reactions in that queue.
   void PopAndInvokeElementQueue();
@@ -275,20 +296,16 @@ class CustomElementRegistry final : publ
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CustomElementRegistry)
 
 public:
   static bool IsCustomElementEnabled(JSContext* aCx = nullptr,
                                      JSObject* aObject = nullptr);
 
-  static void ProcessTopElementQueue();
-
-  static void XPCOMShutdown();
-
   explicit CustomElementRegistry(nsPIDOMWindowInner* aWindow);
 
   /**
    * Looking up a custom element definition.
    * https://html.spec.whatwg.org/#look-up-a-custom-element-definition
    */
   CustomElementDefinition* LookupCustomElementDefinition(
     const nsAString& aLocalName, const nsAString* aIs = nullptr) const;
@@ -311,16 +328,23 @@ public:
   void GetCustomPrototype(nsIAtom* aAtom,
                           JS::MutableHandle<JSObject*> aPrototype);
 
   void Upgrade(Element* aElement, CustomElementDefinition* aDefinition);
 
 private:
   ~CustomElementRegistry();
 
+  UniquePtr<CustomElementCallback> CreateCustomElementCallback(
+    nsIDocument::ElementCallbackType aType, Element* aCustomElement,
+    LifecycleCallbackArgs* aArgs, CustomElementDefinition* aDefinition);
+
+  void SyncInvokeReactions(nsIDocument::ElementCallbackType aType,
+                           Element* aCustomElement,
+                           CustomElementDefinition* aDefinition);
   /**
    * Registers an unresolved custom element that is a candidate for
    * upgrade when the definition is registered via registerElement.
    * |aTypeName| is the name of the custom element type, if it is not
    * provided, then element name is used. |aTypeName| should be provided
    * when registering a custom element that extends an existing
    * element. e.g. <button is="x-button">.
    */
@@ -357,24 +381,16 @@ private:
 
   // The "upgrade candidates map" from the web components spec. Maps from a
   // namespace id and local name to a list of elements to upgrade if that
   // element is registered as a custom element.
   CandidateMap mCandidatesMap;
 
   nsCOMPtr<nsPIDOMWindowInner> mWindow;
 
-  // Array representing the processing stack in the custom elements
-  // specification. The processing stack is conceptually a stack of
-  // element queues. Each queue is represented by a sequence of
-  // CustomElementData in this array, separated by nullptr that
-  // represent the boundaries of the items in the stack. The first
-  // queue in the stack is the base element queue.
-  static mozilla::Maybe<nsTArray<RefPtr<CustomElementData>>> sProcessingStack;
-
   // It is used to prevent reentrant invocations of element definition.
   bool mIsCustomDefinitionRunning;
 
 private:
   class MOZ_RAII AutoSetRunningFlag final {
     public:
       explicit AutoSetRunningFlag(CustomElementRegistry* aRegistry)
         : mRegistry(aRegistry)
@@ -387,16 +403,38 @@ private:
       ~AutoSetRunningFlag() {
         mRegistry->mIsCustomDefinitionRunning = false;
       }
 
     private:
       CustomElementRegistry* mRegistry;
   };
 
+  class SyncInvokeReactionRunnable : public mozilla::Runnable {
+    public:
+      SyncInvokeReactionRunnable(
+        UniquePtr<CustomElementReaction> aReaction, Element* aCustomElement)
+        : Runnable(
+            "dom::CustomElementRegistry::SyncInvokeReactionRunnable")
+        , mReaction(Move(aReaction))
+        , mCustomElement(aCustomElement)
+      {
+      }
+
+      NS_IMETHOD Run() override
+      {
+        mReaction->Invoke(mCustomElement);
+        return NS_OK;
+      }
+
+    private:
+      UniquePtr<CustomElementReaction> mReaction;
+      Element* mCustomElement;
+  };
+
 public:
   nsISupports* GetParentObject() const;
 
   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   void Define(const nsAString& aName, Function& aFunctionConstructor,
               const ElementDefinitionOptions& aOptions, ErrorResult& aRv);
 
--- a/dom/base/FragmentOrElement.cpp
+++ b/dom/base/FragmentOrElement.cpp
@@ -709,18 +709,20 @@ FragmentOrElement::nsDOMSlots::Traverse(
   cb.NoteNativeChild(mExtendedSlots->mXBLBinding,
                      NS_CYCLE_COLLECTION_PARTICIPANT(nsXBLBinding));
 
   NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mExtendedSlots->mXBLInsertionParent");
   cb.NoteXPCOMChild(mExtendedSlots->mXBLInsertionParent.get());
 
   if (mExtendedSlots->mCustomElementData) {
     for (uint32_t i = 0;
-         i < mExtendedSlots->mCustomElementData->mCallbackQueue.Length(); i++) {
-      mExtendedSlots->mCustomElementData->mCallbackQueue[i]->Traverse(cb);
+         i < mExtendedSlots->mCustomElementData->mReactionQueue.Length(); i++) {
+      if (mExtendedSlots->mCustomElementData->mReactionQueue[i]) {
+        mExtendedSlots->mCustomElementData->mReactionQueue[i]->Traverse(cb);
+      }
     }
   }
 
   for (auto iter = mExtendedSlots->mRegisteredIntersectionObservers.Iter();
        !iter.Done(); iter.Next()) {
     DOMIntersectionObserver* observer = iter.Key();
     NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb,
                                        "mExtendedSlots->mRegisteredIntersectionObservers[i]");
--- a/dom/base/TabGroup.h
+++ b/dom/base/TabGroup.h
@@ -20,16 +20,17 @@ class mozIDOMWindowProxy;
 class nsIDocShellTreeItem;
 class nsIDocument;
 class nsPIDOMWindowOuter;
 
 namespace mozilla {
 class AbstractThread;
 class ThrottledEventQueue;
 namespace dom {
+class TabChild;
 
 // Two browsing contexts are considered "related" if they are reachable from one
 // another through window.opener, window.parent, or window.frames. This is the
 // spec concept of a "unit of related browsing contexts"
 //
 // Two browsing contexts are considered "similar-origin" if they can be made to
 // have the same origin by setting document.domain. This is the spec concept of
 // a "unit of similar-origin related browsing contexts"
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -3757,21 +3757,22 @@ nsContentUtils::GetImageFromContent(nsII
     imgRequest.swap(*aRequest);
   }
 
   return imgContainer.forget();
 }
 
 //static
 already_AddRefed<imgRequestProxy>
-nsContentUtils::GetStaticRequest(imgRequestProxy* aRequest)
+nsContentUtils::GetStaticRequest(nsIDocument* aLoadingDocument,
+                                 imgRequestProxy* aRequest)
 {
   NS_ENSURE_TRUE(aRequest, nullptr);
   RefPtr<imgRequestProxy> retval;
-  aRequest->GetStaticRequest(getter_AddRefs(retval));
+  aRequest->GetStaticRequest(aLoadingDocument, getter_AddRefs(retval));
   return retval.forget();
 }
 
 // static
 bool
 nsContentUtils::ContentIsDraggable(nsIContent* aContent)
 {
   nsCOMPtr<nsIDOMHTMLElement> htmlElement = do_QueryInterface(aContent);
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -796,17 +796,18 @@ public:
    * @param aRequest The image request [out]
    * @return the imgIContainer corresponding to the first frame of the image
    */
   static already_AddRefed<imgIContainer> GetImageFromContent(nsIImageLoadingContent* aContent, imgIRequest **aRequest = nullptr);
 
   /**
    * Helper method to call imgIRequest::GetStaticRequest.
    */
-  static already_AddRefed<imgRequestProxy> GetStaticRequest(imgRequestProxy* aRequest);
+  static already_AddRefed<imgRequestProxy> GetStaticRequest(nsIDocument* aLoadingDocument,
+                                                            imgRequestProxy* aRequest);
 
   /**
    * Method that decides whether a content node is draggable
    *
    * @param aContent The content node to test.
    * @return whether it's draggable
    */
   static bool ContentIsDraggable(nsIContent* aContent);
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -4121,16 +4121,22 @@ nsDocument::IsNodeOfType(uint32_t aFlags
 
 Element*
 nsIDocument::GetRootElement() const
 {
   return (mCachedRootElement && mCachedRootElement->GetParentNode() == this) ?
          mCachedRootElement : GetRootElementInternal();
 }
 
+nsIContent*
+nsIDocument::GetUnfocusedKeyEventTarget()
+{
+  return GetRootElement();
+}
+
 Element*
 nsDocument::GetRootElementInternal() const
 {
   // We invoke GetRootElement() immediately before the servo traversal, so we
   // should always have a cache hit from Servo.
   MOZ_ASSERT(NS_IsMainThread());
 
   // Loop backwards because any non-elements, such as doctypes and PIs
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -934,16 +934,22 @@ public:
   mozilla::dom::DocumentType* GetDoctype() const;
 
   /**
    * Return the root element for this document.
    */
   Element* GetRootElement() const;
 
   /**
+   * Gets the event target to dispatch key events to if there is no focused
+   * content in the document.
+   */
+  virtual nsIContent* GetUnfocusedKeyEventTarget();
+
+  /**
    * Retrieve information about the viewport as a data structure.
    * This will return information in the viewport META data section
    * of the document. This can be used in lieu of ProcessViewportInfo(),
    * which places the viewport information in the document header instead
    * of returning it directly.
    *
    * @param aDisplaySize size of the on-screen display area for this
    * document, in device pixels.
--- a/dom/base/nsIImageLoadingContent.idl
+++ b/dom/base/nsIImageLoadingContent.idl
@@ -76,23 +76,35 @@ interface nsIImageLoadingContent : imgIN
    * Notifications from ongoing image loads will be passed to all
    * registered observers.  Notifications for all request types,
    * current and pending, will be passed through.
    *
    * @param aObserver the observer to register
    *
    * @throws NS_ERROR_OUT_OF_MEMORY
    */
-  void addObserver(in imgINotificationObserver aObserver);
+  [notxpcom] nsresult addNativeObserver(in imgINotificationObserver aObserver);
 
   /**
    * Used to unregister an image decoder observer.
    *
    * @param aObserver the observer to unregister
    */
+  [notxpcom] nsresult removeNativeObserver(in imgINotificationObserver aObserver);
+
+  /**
+   * Same as addNativeObserver but intended for scripted observers or observers
+   * from another or without a document.
+   */
+  void addObserver(in imgINotificationObserver aObserver);
+
+  /**
+   * Same as removeNativeObserver but intended for scripted observers or
+   * observers from another or without a document.
+   */
   void removeObserver(in imgINotificationObserver aObserver);
   
   /**
    * Accessor to get the image requests
    *
    * @param aRequestType a value saying which request is wanted
    *
    * @return the imgIRequest object (may be null, even when no error
--- a/dom/base/nsImageLoadingContent.cpp
+++ b/dom/base/nsImageLoadingContent.cpp
@@ -118,16 +118,18 @@ nsImageLoadingContent::DestroyImageLoadi
 }
 
 nsImageLoadingContent::~nsImageLoadingContent()
 {
   NS_ASSERTION(!mCurrentRequest && !mPendingRequest,
                "DestroyImageLoadingContent not called");
   NS_ASSERTION(!mObserverList.mObserver && !mObserverList.mNext,
                "Observers still registered?");
+  NS_ASSERTION(mScriptedObservers.IsEmpty(),
+               "Scripted observers still registered?");
 }
 
 /*
  * imgINotificationObserver impl
  */
 NS_IMETHODIMP
 nsImageLoadingContent::Notify(imgIRequest* aRequest,
                               int32_t aType,
@@ -382,17 +384,17 @@ ReplayImageStatus(imgIRequest* aRequest,
     aObserver->Notify(aRequest, imgINotificationObserver::DECODE_COMPLETE, nullptr);
   }
   if (status & imgIRequest::STATUS_LOAD_COMPLETE) {
     aObserver->Notify(aRequest, imgINotificationObserver::LOAD_COMPLETE, nullptr);
   }
 }
 
 NS_IMETHODIMP
-nsImageLoadingContent::AddObserver(imgINotificationObserver* aObserver)
+nsImageLoadingContent::AddNativeObserver(imgINotificationObserver* aObserver)
 {
   NS_ENSURE_ARG_POINTER(aObserver);
 
   if (!mObserverList.mObserver) {
     // Don't touch the linking of the list!
     mObserverList.mObserver = aObserver;
 
     ReplayImageStatus(mCurrentRequest, aObserver);
@@ -411,17 +413,17 @@ nsImageLoadingContent::AddObserver(imgIN
   observer->mNext = new ImageObserver(aObserver);
   ReplayImageStatus(mCurrentRequest, aObserver);
   ReplayImageStatus(mPendingRequest, aObserver);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsImageLoadingContent::RemoveObserver(imgINotificationObserver* aObserver)
+nsImageLoadingContent::RemoveNativeObserver(imgINotificationObserver* aObserver)
 {
   NS_ENSURE_ARG_POINTER(aObserver);
 
   if (mObserverList.mObserver == aObserver) {
     mObserverList.mObserver = nullptr;
     // Don't touch the linking of the list!
     return NS_OK;
   }
@@ -444,16 +446,167 @@ nsImageLoadingContent::RemoveObserver(im
 #ifdef DEBUG
   else {
     NS_WARNING("Asked to remove nonexistent observer");
   }
 #endif
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsImageLoadingContent::AddObserver(imgINotificationObserver* aObserver)
+{
+  NS_ENSURE_ARG_POINTER(aObserver);
+
+  nsresult rv = NS_OK;
+  RefPtr<imgRequestProxy> currentReq;
+  if (mCurrentRequest) {
+    // Scripted observers may not belong to the same document as us, so when we
+    // create the imgRequestProxy, we shouldn't use any. This allows the request
+    // to dispatch notifications from the correct scheduler group.
+    rv = mCurrentRequest->Clone(aObserver, nullptr, getter_AddRefs(currentReq));
+    if (NS_FAILED(rv)) {
+      return rv;
+    }
+  }
+
+  RefPtr<imgRequestProxy> pendingReq;
+  if (mPendingRequest) {
+    // See above for why we don't use the loading document.
+    rv = mPendingRequest->Clone(aObserver, nullptr, getter_AddRefs(pendingReq));
+    if (NS_FAILED(rv)) {
+      mCurrentRequest->CancelAndForgetObserver(NS_BINDING_ABORTED);
+      return rv;
+    }
+  }
+
+  mScriptedObservers.AppendElement(
+    new ScriptedImageObserver(aObserver, Move(currentReq), Move(pendingReq)));
+  return rv;
+}
+
+NS_IMETHODIMP
+nsImageLoadingContent::RemoveObserver(imgINotificationObserver* aObserver)
+{
+  NS_ENSURE_ARG_POINTER(aObserver);
+
+  if (NS_WARN_IF(mScriptedObservers.IsEmpty())) {
+    return NS_OK;
+  }
+
+  RefPtr<ScriptedImageObserver> observer;
+  auto i = mScriptedObservers.Length();
+  do {
+    --i;
+    if (mScriptedObservers[i]->mObserver == aObserver) {
+      observer = Move(mScriptedObservers[i]);
+      mScriptedObservers.RemoveElementAt(i);
+      break;
+    }
+  } while(i > 0);
+
+  if (NS_WARN_IF(!observer)) {
+    return NS_OK;
+  }
+
+  // If the cancel causes a mutation, it will be harmless, because we have
+  // already removed the observer from the list.
+  observer->CancelRequests();
+  return NS_OK;
+}
+
+void
+nsImageLoadingContent::ClearScriptedRequests(int32_t aRequestType, nsresult aReason)
+{
+  if (MOZ_LIKELY(mScriptedObservers.IsEmpty())) {
+    return;
+  }
+
+  nsTArray<RefPtr<ScriptedImageObserver>> observers(mScriptedObservers);
+  auto i = observers.Length();
+  do {
+    --i;
+
+    RefPtr<imgRequestProxy> req;
+    switch (aRequestType) {
+    case CURRENT_REQUEST:
+      req = Move(observers[i]->mCurrentRequest);
+      break;
+    case PENDING_REQUEST:
+      req = Move(observers[i]->mPendingRequest);
+      break;
+    default:
+      NS_ERROR("Unknown request type");
+      return;
+    }
+
+    if (req) {
+      req->CancelAndForgetObserver(aReason);
+    }
+  } while (i > 0);
+}
+
+void
+nsImageLoadingContent::CloneScriptedRequests(imgRequestProxy* aRequest)
+{
+  MOZ_ASSERT(aRequest);
+
+  if (MOZ_LIKELY(mScriptedObservers.IsEmpty())) {
+    return;
+  }
+
+  bool current;
+  if (aRequest == mCurrentRequest) {
+    current = true;
+  } else if (aRequest == mPendingRequest) {
+    current = false;
+  } else {
+    MOZ_ASSERT_UNREACHABLE("Unknown request type");
+    return;
+  }
+
+  nsTArray<RefPtr<ScriptedImageObserver>> observers(mScriptedObservers);
+  auto i = observers.Length();
+  do {
+    --i;
+
+    ScriptedImageObserver* observer = observers[i];
+    RefPtr<imgRequestProxy>& req = current ? observer->mCurrentRequest
+                                           : observer->mPendingRequest;
+    if (NS_WARN_IF(req)) {
+      MOZ_ASSERT_UNREACHABLE("Should have cancelled original request");
+      req->CancelAndForgetObserver(NS_BINDING_ABORTED);
+      req = nullptr;
+    }
+
+    nsresult rv = aRequest->Clone(observer->mObserver, nullptr, getter_AddRefs(req));
+    Unused << NS_WARN_IF(NS_FAILED(rv));
+  } while (i > 0);
+}
+
+void
+nsImageLoadingContent::MakePendingScriptedRequestsCurrent()
+{
+  if (MOZ_LIKELY(mScriptedObservers.IsEmpty())) {
+    return;
+  }
+
+  nsTArray<RefPtr<ScriptedImageObserver>> observers(mScriptedObservers);
+  auto i = observers.Length();
+  do {
+    --i;
+
+    ScriptedImageObserver* observer = observers[i];
+    if (observer->mCurrentRequest) {
+      observer->mCurrentRequest->CancelAndForgetObserver(NS_BINDING_ABORTED);
+    }
+    observer->mCurrentRequest = Move(observer->mPendingRequest);
+  } while (i > 0);
+}
+
 already_AddRefed<imgIRequest>
 nsImageLoadingContent::GetRequest(int32_t aRequestType,
                                   ErrorResult& aError)
 {
   nsCOMPtr<imgIRequest> request;
   switch(aRequestType) {
   case CURRENT_REQUEST:
     request = mCurrentRequest;
@@ -628,16 +781,17 @@ nsImageLoadingContent::LoadImageWithChan
   // Our state might change. Watch it.
   AutoStateChanger changer(this, true);
 
   // Do the load.
   RefPtr<imgRequestProxy>& req = PrepareNextRequest(eImageLoadType_Normal);
   nsresult rv = loader->
     LoadImageWithChannel(aChannel, this, doc, aListener, getter_AddRefs(req));
   if (NS_SUCCEEDED(rv)) {
+    CloneScriptedRequests(req);
     TrackImage(req);
     ResetAnimationIfNeeded();
     return NS_OK;
   }
 
   MOZ_ASSERT(!req, "Shouldn't have non-null request here");
   // If we don't have a current URI, we might as well store this URI so people
   // know what we tried (and failed) to load.
@@ -905,16 +1059,17 @@ nsImageLoadingContent::LoadImage(nsIURI*
   mUseUrgentStartForChannel = false;
 
   // Tell the document to forget about the image preload, if any, for
   // this URI, now that we might have another imgRequestProxy for it.
   // That way if we get canceled later the image load won't continue.
   aDocument->ForgetImagePreload(aNewURI);
 
   if (NS_SUCCEEDED(rv)) {
+    CloneScriptedRequests(req);
     TrackImage(req);
     ResetAnimationIfNeeded();
 
     // Handle cases when we just ended up with a pending request but it's
     // already done.  In that situation we have to synchronously switch that
     // request to being the current request, because websites depend on that
     // behavior.
     if (req == mPendingRequest) {
@@ -1078,18 +1233,19 @@ nsImageLoadingContent::UseAsPrimaryReque
   AutoStateChanger changer(this, aNotify);
 
   // Get rid if our existing images
   ClearPendingRequest(NS_BINDING_ABORTED, Some(OnNonvisible::DISCARD_IMAGES));
   ClearCurrentRequest(NS_BINDING_ABORTED, Some(OnNonvisible::DISCARD_IMAGES));
 
   // Clone the request we were given.
   RefPtr<imgRequestProxy>& req = PrepareNextRequest(aImageLoadType);
-  nsresult rv = aRequest->Clone(this, getter_AddRefs(req));
+  nsresult rv = aRequest->SyncClone(this, GetOurOwnerDoc(), getter_AddRefs(req));
   if (NS_SUCCEEDED(rv)) {
+    CloneScriptedRequests(req);
     TrackImage(req);
   } else {
     MOZ_ASSERT(!req, "Shouldn't have non-null request here");
     return rv;
   }
 
   return NS_OK;
 }
@@ -1329,16 +1485,17 @@ nsImageLoadingContent::MakePendingReques
   // to go to 0 and the image to be discarded!
   ImageRequestAutoLock autoLock(mCurrentRequest);
 
   ImageLoadType loadType = \
     (mPendingRequestFlags & REQUEST_IS_IMAGESET) ? eImageLoadType_Imageset
                                                  : eImageLoadType_Normal;
 
   PrepareCurrentRequest(loadType) = mPendingRequest;
+  MakePendingScriptedRequestsCurrent();
   mPendingRequest = nullptr;
   mCurrentRequestFlags = mPendingRequestFlags;
   mPendingRequestFlags = 0;
   mCurrentRequestRegistered = mPendingRequestRegistered;
   mPendingRequestRegistered = false;
   ResetAnimationIfNeeded();
 }
 
@@ -1358,16 +1515,17 @@ nsImageLoadingContent::ClearCurrentReque
 
   // Deregister this image from the refresh driver so it no longer receives
   // notifications.
   nsLayoutUtils::DeregisterImageRequest(GetFramePresContext(), mCurrentRequest,
                                         &mCurrentRequestRegistered);
 
   // Clean up the request.
   UntrackImage(mCurrentRequest, aNonvisibleAction);
+  ClearScriptedRequests(CURRENT_REQUEST, aReason);
   mCurrentRequest->CancelAndForgetObserver(aReason);
   mCurrentRequest = nullptr;
   mCurrentRequestFlags = 0;
 }
 
 void
 nsImageLoadingContent::ClearPendingRequest(nsresult aReason,
                                            const Maybe<OnNonvisible>& aNonvisibleAction)
@@ -1376,16 +1534,17 @@ nsImageLoadingContent::ClearPendingReque
     return;
 
   // Deregister this image from the refresh driver so it no longer receives
   // notifications.
   nsLayoutUtils::DeregisterImageRequest(GetFramePresContext(), mPendingRequest,
                                         &mPendingRequestRegistered);
 
   UntrackImage(mPendingRequest, aNonvisibleAction);
+  ClearScriptedRequests(PENDING_REQUEST, aReason);
   mPendingRequest->CancelAndForgetObserver(aReason);
   mPendingRequest = nullptr;
   mPendingRequestFlags = 0;
 }
 
 bool*
 nsImageLoadingContent::GetRegisteredFlagForRequest(imgIRequest* aRequest)
 {
@@ -1563,17 +1722,22 @@ nsImageLoadingContent::UntrackImage(imgI
     }
   }
 }
 
 
 void
 nsImageLoadingContent::CreateStaticImageClone(nsImageLoadingContent* aDest) const
 {
-  aDest->mCurrentRequest = nsContentUtils::GetStaticRequest(mCurrentRequest);
+  aDest->ClearScriptedRequests(CURRENT_REQUEST, NS_BINDING_ABORTED);
+  aDest->mCurrentRequest =
+    nsContentUtils::GetStaticRequest(aDest->GetOurOwnerDoc(), mCurrentRequest);
+  if (aDest->mCurrentRequest) {
+    aDest->CloneScriptedRequests(aDest->mCurrentRequest);
+  }
   aDest->TrackImage(aDest->mCurrentRequest);
   aDest->mForcedImageState = mForcedImageState;
   aDest->mImageBlockingStatus = mImageBlockingStatus;
   aDest->mLoadingEnabled = mLoadingEnabled;
   aDest->mStateChangerDepth = mStateChangerDepth;
   aDest->mIsImageStateForced = mIsImageStateForced;
   aDest->mLoading = mLoading;
   aDest->mBroken = mBroken;
@@ -1595,15 +1759,47 @@ nsImageLoadingContent::ImageObserver::Im
 }
 
 nsImageLoadingContent::ImageObserver::~ImageObserver()
 {
   MOZ_COUNT_DTOR(ImageObserver);
   NS_CONTENT_DELETE_LIST_MEMBER(ImageObserver, this, mNext);
 }
 
+nsImageLoadingContent::ScriptedImageObserver::ScriptedImageObserver(imgINotificationObserver* aObserver,
+                                                                    RefPtr<imgRequestProxy>&& aCurrentRequest,
+                                                                    RefPtr<imgRequestProxy>&& aPendingRequest)
+  : mObserver(aObserver)
+  , mCurrentRequest(aCurrentRequest)
+  , mPendingRequest(aPendingRequest)
+{ }
+
+nsImageLoadingContent::ScriptedImageObserver::~ScriptedImageObserver()
+{
+  // We should have cancelled any requests before getting released.
+  DebugOnly<bool> cancel = CancelRequests();
+  MOZ_ASSERT(!cancel, "Still have requests in ~ScriptedImageObserver!");
+}
+
+bool
+nsImageLoadingContent::ScriptedImageObserver::CancelRequests()
+{
+  bool cancelled = false;
+  if (mCurrentRequest) {
+    mCurrentRequest->CancelAndForgetObserver(NS_BINDING_ABORTED);
+    mCurrentRequest = nullptr;
+    cancelled = true;
+  }
+  if (mPendingRequest) {
+    mPendingRequest->CancelAndForgetObserver(NS_BINDING_ABORTED);
+    mPendingRequest = nullptr;
+    cancelled = true;
+  }
+  return cancelled;
+}
+
 // Only HTMLInputElement.h overrides this for <img> tags
 // all other subclasses use this one, i.e. ignore referrer attributes
 mozilla::net::ReferrerPolicy
 nsImageLoadingContent::GetImageReferrerPolicy()
 {
   return mozilla::net::RP_Unset;
 };
--- a/dom/base/nsImageLoadingContent.h
+++ b/dom/base/nsImageLoadingContent.h
@@ -220,27 +220,47 @@ protected:
   void AsyncEventRunning(mozilla::AsyncEventDispatcher* aEvent);
 
   // Get ourselves as an nsIContent*.  Not const because some of the callers
   // want a non-const nsIContent.
   virtual nsIContent* AsContent() = 0;
 
 private:
   /**
-   * Struct used to manage the image observers.
+   * Struct used to manage the native image observers.
    */
   struct ImageObserver {
     explicit ImageObserver(imgINotificationObserver* aObserver);
     ~ImageObserver();
 
     nsCOMPtr<imgINotificationObserver> mObserver;
     ImageObserver* mNext;
   };
 
   /**
+   * Struct used to manage the scripted/XPCOM image observers.
+   */
+  class ScriptedImageObserver final {
+  public:
+    NS_INLINE_DECL_REFCOUNTING(ScriptedImageObserver)
+
+    ScriptedImageObserver(imgINotificationObserver* aObserver,
+                          RefPtr<imgRequestProxy>&& aCurrentRequest,
+                          RefPtr<imgRequestProxy>&& aPendingRequest);
+    bool CancelRequests();
+
+    nsCOMPtr<imgINotificationObserver> mObserver;
+    RefPtr<imgRequestProxy> mCurrentRequest;
+    RefPtr<imgRequestProxy> mPendingRequest;
+
+  private:
+    ~ScriptedImageObserver();
+  };
+
+  /**
    * Struct to report state changes
    */
   struct AutoStateChanger {
     AutoStateChanger(nsImageLoadingContent* aImageContent,
                      bool aNotify) :
       mImageContent(aImageContent),
       mNotify(aNotify)
     {
@@ -398,26 +418,51 @@ protected:
   // If the image was blocked or if there was an error loading, it's nice to
   // still keep track of what the URI was despite not having an imgIRequest.
   // We only maintain this in those situations (in the common case, this is
   // always null).
   nsCOMPtr<nsIURI>      mCurrentURI;
 
 private:
   /**
+   * Clones the given "current" or "pending" request for each scripted observer.
+   */
+  void CloneScriptedRequests(imgRequestProxy* aRequest);
+
+  /**
+   * Cancels and nulls-out the "current" or "pending" requests if they exist
+   * for each scripted observer.
+   */
+  void ClearScriptedRequests(int32_t aRequestType, nsresult aReason);
+
+  /**
+   * Moves the "pending" request into the "current" request for each scripted
+   * observer. If there is an existing "current" request, it will cancel it
+   * first.
+   */
+  void MakePendingScriptedRequestsCurrent();
+
+  /**
    * Typically we will have only one observer (our frame in the screen
    * prescontext), so we want to only make space for one and to
    * heap-allocate anything past that (saves memory and malloc churn
    * in the common case).  The storage is a linked list, we just
    * happen to actually hold the first observer instead of a pointer
    * to it.
    */
   ImageObserver mObserverList;
 
   /**
+   * Typically we will have no scripted observers, as this is only used by
+   * chrome, legacy extensions, and some mochitests. An empty array reserves
+   * minimal memory.
+   */
+  nsTArray<RefPtr<ScriptedImageObserver>> mScriptedObservers;
+
+  /**
    * When mIsImageStateForced is true, this holds the ImageState that we'll
    * return in ImageState().
    */
   mozilla::EventStates mForcedImageState;
 
   mozilla::TimeStamp mMostRecentRequestChange;
 
   int16_t mImageBlockingStatus;
--- a/dom/canvas/BasicRenderingContext2D.h
+++ b/dom/canvas/BasicRenderingContext2D.h
@@ -5,18 +5,18 @@
 #ifndef BasicRenderingContext2D_h
 #define BasicRenderingContext2D_h
 
 #include "mozilla/dom/CanvasRenderingContext2DBinding.h"
 
 namespace mozilla {
 namespace dom {
 
-class HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap;
-typedef HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap
+class HTMLImageElementOrSVGImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap;
+typedef HTMLImageElementOrSVGImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap
   CanvasImageSource;
 
 /*
  * BasicRenderingContext2D
  */
 class BasicRenderingContext2D
 {
 public:
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -102,16 +102,17 @@
 #include "mozilla/UniquePtr.h"
 #include "mozilla/Unused.h"
 #include "nsCCUncollectableMarker.h"
 #include "nsWrapperCacheInlines.h"
 #include "mozilla/dom/CanvasRenderingContext2DBinding.h"
 #include "mozilla/dom/CanvasPath.h"
 #include "mozilla/dom/HTMLImageElement.h"
 #include "mozilla/dom/HTMLVideoElement.h"
+#include "mozilla/dom/SVGImageElement.h"
 #include "mozilla/dom/SVGMatrix.h"
 #include "mozilla/dom/TextMetrics.h"
 #include "mozilla/dom/SVGMatrix.h"
 #include "mozilla/FloatingPoint.h"
 #include "nsGlobalWindow.h"
 #include "GLContext.h"
 #include "GLContextProvider.h"
 #include "SVGContentUtils.h"
@@ -2524,20 +2525,20 @@ CanvasRenderingContext2D::CreatePattern(
     repeatMode = CanvasPattern::RepeatMode::REPEATY;
   } else if (aRepeat.EqualsLiteral("no-repeat")) {
     repeatMode = CanvasPattern::RepeatMode::NOREPEAT;
   } else {
     aError.Throw(NS_ERROR_DOM_SYNTAX_ERR);
     return nullptr;
   }
 
-  Element* htmlElement;
+  Element* element;
   if (aSource.IsHTMLCanvasElement()) {
     HTMLCanvasElement* canvas = &aSource.GetAsHTMLCanvasElement();
-    htmlElement = canvas;
+    element = canvas;
 
     nsIntSize size = canvas->GetSize();
     if (size.width == 0 || size.height == 0) {
       aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
       return nullptr;
     }
 
     // Special case for Canvas, which could be an Azure canvas!
@@ -2552,32 +2553,40 @@ CanvasRenderingContext2D::CreatePattern(
                                 "CanvasRenderingContext2D.createPattern()"
                                 " failed to snapshot source canvas.");
         }
         aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
         return nullptr;
       }
 
       RefPtr<CanvasPattern> pat =
-        new CanvasPattern(this, srcSurf, repeatMode, htmlElement->NodePrincipal(), canvas->IsWriteOnly(), false);
+        new CanvasPattern(this, srcSurf, repeatMode, element->NodePrincipal(), canvas->IsWriteOnly(), false);
 
       return pat.forget();
     }
   } else if (aSource.IsHTMLImageElement()) {
     HTMLImageElement* img = &aSource.GetAsHTMLImageElement();
     if (img->IntrinsicState().HasState(NS_EVENT_STATE_BROKEN)) {
       aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
       return nullptr;
     }
 
-    htmlElement = img;
+    element = img;
+  } else if (aSource.IsSVGImageElement()) {
+    SVGImageElement* img = &aSource.GetAsSVGImageElement();
+    if (img->IntrinsicState().HasState(NS_EVENT_STATE_BROKEN)) {
+      aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+      return nullptr;
+    }
+
+    element = img;
   } else if (aSource.IsHTMLVideoElement()) {
     auto& video = aSource.GetAsHTMLVideoElement();
     video.MarkAsContentSource(mozilla::dom::HTMLVideoElement::CallerAPI::CREATE_PATTERN);
-    htmlElement = &video;
+    element = &video;
   } else {
     // Special case for ImageBitmap
     ImageBitmap& imgBitmap = aSource.GetAsImageBitmap();
     EnsureTarget();
     if (!IsTargetValid()) {
       aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
       return nullptr;
     }
@@ -2606,17 +2615,17 @@ CanvasRenderingContext2D::CreatePattern(
   if (!IsTargetValid()) {
     aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return nullptr;
   }
 
   // The canvas spec says that createPattern should use the first frame
   // of animated images
   nsLayoutUtils::SurfaceFromElementResult res =
-    nsLayoutUtils::SurfaceFromElement(htmlElement,
+    nsLayoutUtils::SurfaceFromElement(element,
       nsLayoutUtils::SFE_WANT_FIRST_FRAME_IF_IMAGE, mTarget);
 
   if (!res.GetSourceSurface()) {
     return nullptr;
   }
 
   RefPtr<CanvasPattern> pat = new CanvasPattern(this, res.GetSourceSurface(), repeatMode,
                                                 res.mPrincipal, res.mIsWriteOnly,
@@ -5172,16 +5181,19 @@ CanvasRenderingContext2D::DrawImage(cons
     }
 
     imgSize = gfx::IntSize(imageBitmap.Width(), imageBitmap.Height());
   }
   else {
     if (aImage.IsHTMLImageElement()) {
       HTMLImageElement* img = &aImage.GetAsHTMLImageElement();
       element = img;
+    } else if (aImage.IsSVGImageElement()) {
+      SVGImageElement* img = &aImage.GetAsSVGImageElement();
+      element = img;
     } else {
       HTMLVideoElement* video = &aImage.GetAsHTMLVideoElement();
       video->MarkAsContentSource(mozilla::dom::HTMLVideoElement::CallerAPI::DRAW_IMAGE);
       element = video;
     }
 
     srcSurf =
      CanvasImageCache::LookupCanvas(element, mCanvasElement, &imgSize, mIsSkiaGL);
--- a/dom/canvas/CanvasRenderingContext2D.h
+++ b/dom/canvas/CanvasRenderingContext2D.h
@@ -35,18 +35,18 @@ class nsGlobalWindow;
 class nsXULElement;
 
 namespace mozilla {
 namespace gl {
 class SourceSurface;
 } // namespace gl
 
 namespace dom {
-class HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap;
-typedef HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap CanvasImageSource;
+class HTMLImageElementOrSVGImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap;
+typedef HTMLImageElementOrSVGImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmap CanvasImageSource;
 class ImageData;
 class StringOrCanvasGradientOrCanvasPattern;
 class OwningStringOrCanvasGradientOrCanvasPattern;
 class TextMetrics;
 class CanvasFilterChainObserver;
 class CanvasPath;
 
 extern const mozilla::gfx::Float SIGMA_MAX;
--- a/dom/canvas/WebGLContextExtensions.cpp
+++ b/dom/canvas/WebGLContextExtensions.cpp
@@ -5,16 +5,17 @@
 
 #include "WebGLContext.h"
 #include "WebGLContextUtils.h"
 #include "WebGLExtensions.h"
 #include "gfxPrefs.h"
 #include "GLContext.h"
 
 #include "nsString.h"
+#include "nsContentUtils.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/dom/BindingDeclarations.h"
 #include "AccessCheck.h"
 
 namespace mozilla {
 
 /*static*/ const char*
 WebGLContext::GetExtensionString(WebGLExtensionID ext)
@@ -141,17 +142,18 @@ WebGLContext::IsExtensionSupported(WebGL
         return gl->IsExtensionSupported(gl::GLContext::IMG_texture_compression_pvrtc);
     case WebGLExtensionID::WEBGL_compressed_texture_s3tc:
         return WebGLExtensionCompressedTextureS3TC::IsSupported(this);
     case WebGLExtensionID::WEBGL_compressed_texture_s3tc_srgb:
         return WebGLExtensionCompressedTextureS3TC::IsSupported(this) &&
                gl->IsExtensionSupported(gl::GLContext::EXT_texture_sRGB);
     case WebGLExtensionID::WEBGL_debug_renderer_info:
         return Preferences::GetBool("webgl.enable-debug-renderer-info", false);
-
+    case WebGLExtensionID::WEBGL_debug_shaders:
+        return !nsContentUtils::ShouldResistFingerprinting();
     case WebGLExtensionID::WEBGL_lose_context:
         // We always support this extension.
         return true;
 
     default:
         // For warnings-as-errors.
         break;
     }
--- a/dom/canvas/WebGLShader.cpp
+++ b/dom/canvas/WebGLShader.cpp
@@ -274,22 +274,16 @@ WebGLShader::GetShaderSource(nsAString* 
 {
     out->SetIsVoid(false);
     *out = mSource;
 }
 
 void
 WebGLShader::GetShaderTranslatedSource(nsAString* out) const
 {
-    if (!mCompilationSuccessful) {
-        mContext->ErrorInvalidOperation("getShaderTranslatedSource: Shader has"
-                                        " not been successfully compiled.");
-        return;
-    }
-
     out->SetIsVoid(false);
     CopyASCIItoUTF16(mTranslatedSource, *out);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 bool
 WebGLShader::CanLinkTo(const WebGLShader* prev, nsCString* const out_log) const
--- a/dom/canvas/test/webgl-mochitest/ensure-exts/test_common.html
+++ b/dom/canvas/test/webgl-mochitest/ensure-exts/test_common.html
@@ -27,17 +27,17 @@ var defaultExts = [
     ['OES_standard_derivatives'      , [MACHINE_SPECIFIC, FORBID          ]],
     ['OES_texture_float'             , [ENSURE          , FORBID          ]],
     ['OES_texture_float_linear'      , [ENSURE          , ENSURE          ]],
     ['OES_texture_half_float'        , [ENSURE          , FORBID          ]],
     ['OES_texture_half_float_linear' , [ENSURE          , FORBID          ]],
     ['OES_vertex_array_object'       , [ENSURE          , FORBID          ]],
     ['WEBGL_compressed_texture_s3tc' , [MACHINE_SPECIFIC, MACHINE_SPECIFIC]],
     ['WEBGL_debug_renderer_info'     , [ENSURE          , ENSURE          ]],
-    ['WEBGL_debug_shaders'           , [FORBID          , FORBID          ]],
+    ['WEBGL_debug_shaders'           , [ENSURE          , ENSURE          ]],
     ['WEBGL_depth_texture'           , [MACHINE_SPECIFIC, FORBID          ]],
     ['WEBGL_draw_buffers'            , [MACHINE_SPECIFIC, FORBID          ]],
     ['WEBGL_lose_context'            , [ENSURE          , ENSURE          ]],
 
     // Community Approved
     ['EXT_color_buffer_float'        , [FORBID          , ENSURE          ]],
     ['EXT_color_buffer_half_float'   , [MACHINE_SPECIFIC, FORBID          ]],
     ['EXT_sRGB'                      , [MACHINE_SPECIFIC, FORBID          ]],
--- a/dom/canvas/test/webgl-mochitest/test_privileged_exts.html
+++ b/dom/canvas/test/webgl-mochitest/test_privileged_exts.html
@@ -19,14 +19,14 @@ function TestExt(gl, name) {
 (function() {
   var gl = WebGLUtil.getWebGL('c');
   if (!gl) {
     todo(gl, 'Get GL working here first.');
     return;
   }
 
   // Privileged extensions:
-  TestExt(gl, 'WEBGL_debug_shaders');
+  TestExt(gl, 'MOZ_debug');
 })();
 
 </script>
 </body>
 </html>
--- a/dom/html/ImageDocument.cpp
+++ b/dom/html/ImageDocument.cpp
@@ -116,17 +116,17 @@ ImageListener::OnStartRequest(nsIRequest
     request->Cancel(NS_ERROR_CONTENT_BLOCKED);
     return NS_OK;
   }
 
   if (!imgDoc->mObservingImageLoader) {
     nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(imgDoc->mImageContent);
     NS_ENSURE_TRUE(imageLoader, NS_ERROR_UNEXPECTED);
 
-    imageLoader->AddObserver(imgDoc);
+    imageLoader->AddNativeObserver(imgDoc);
     imgDoc->mObservingImageLoader = true;
     imageLoader->LoadImageWithChannel(channel, getter_AddRefs(mNextStream));
   }
 
   return MediaDocumentStreamListener::OnStartRequest(request, ctxt);
 }
 
 NS_IMETHODIMP
@@ -227,17 +227,17 @@ ImageDocument::Destroy()
     nsCOMPtr<EventTarget> target = do_QueryInterface(mImageContent);
     target->RemoveEventListener(NS_LITERAL_STRING("load"), this, false);
     target->RemoveEventListener(NS_LITERAL_STRING("click"), this, false);
 
     // Break reference cycle with mImageContent, if we have one
     if (mObservingImageLoader) {
       nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageContent);
       if (imageLoader) {
-        imageLoader->RemoveObserver(this);
+        imageLoader->RemoveNativeObserver(this);
       }
     }
 
     mImageContent = nullptr;
   }
 
   MediaDocument::Destroy();
 }
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -878,16 +878,25 @@ nsHTMLDocument::SetCompatibilityMode(nsC
   if (shell) {
     nsPresContext *pc = shell->GetPresContext();
     if (pc) {
       pc->CompatibilityModeChanged();
     }
   }
 }
 
+nsIContent*
+nsHTMLDocument::GetUnfocusedKeyEventTarget()
+{
+  if (nsGenericHTMLElement* body = GetBody()) {
+    return body;
+  }
+  return nsDocument::GetUnfocusedKeyEventTarget();
+}
+
 //
 // nsIDOMHTMLDocument interface implementation
 //
 already_AddRefed<nsIURI>
 nsHTMLDocument::GetDomainURI()
 {
   nsIPrincipal* principal = NodePrincipal();
 
--- a/dom/html/nsHTMLDocument.h
+++ b/dom/html/nsHTMLDocument.h
@@ -69,16 +69,18 @@ public:
   // nsIHTMLDocument
   virtual void SetCompatibilityMode(nsCompatibility aMode) override;
 
   virtual bool IsWriting() override
   {
     return mWriteLevel != uint32_t(0);
   }
 
+  virtual nsIContent* GetUnfocusedKeyEventTarget() override;
+
   virtual nsContentList* GetForms() override;
 
   virtual nsContentList* GetFormControls() override;
 
   // nsIDOMDocument interface
   using nsDocument::CreateElement;
   using nsDocument::CreateElementNS;
   NS_FORWARD_NSIDOMDOCUMENT(nsDocument::)
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -1613,21 +1613,24 @@ ScriptLoader::AttemptAsyncScriptCompile(
   JS::Rooted<JSObject*> global(cx, globalObject->GetGlobalJSObject());
   JS::CompileOptions options(cx);
 
   nsresult rv = FillCompileOptionsForRequest(jsapi, aRequest, global, &options);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  size_t len = aRequest->IsSource()
-    ? aRequest->mScriptText.length()
-    : aRequest->mScriptBytecode.length();
-  if (!JS::CanCompileOffThread(cx, options, len)) {
-    return NS_ERROR_FAILURE;
+  if (aRequest->IsSource()) {
+    if (!JS::CanCompileOffThread(cx, options, aRequest->mScriptText.length())) {
+      return NS_ERROR_FAILURE;
+    }
+  } else {
+    if (!JS::CanDecodeOffThread(cx, options, aRequest->mScriptBytecode.length())) {
+      return NS_ERROR_FAILURE;
+    }
   }
 
   RefPtr<NotifyOffThreadScriptLoadCompletedRunnable> runnable =
     new NotifyOffThreadScriptLoadCompletedRunnable(aRequest, this);
 
   if (aRequest->IsModuleRequest()) {
     MOZ_ASSERT(aRequest->IsSource());
     if (!JS::CompileOffThreadModule(cx, options,
--- a/dom/tests/mochitest/webcomponents/test_document_register_stack.html
+++ b/dom/tests/mochitest/webcomponents/test_document_register_stack.html
@@ -23,25 +23,25 @@ function testChangeAttributeInCreatedCal
   var attributeChangedCallbackCalled = false;
 
   var p = Object.create(HTMLElement.prototype);
   p.createdCallback = function() {
     is(createdCallbackCalled, false, "Created callback should be called before attached callback.");
     createdCallbackCalled = true;
     is(attributeChangedCallbackCalled, false, "Attribute changed callback should not have been called prior to setting the attribute.");
     this.setAttribute("foo", "bar");
-    is(attributeChangedCallbackCalled, false, "While element is being created, element should not be added to the current element callback queue.");
+    is(attributeChangedCallbackCalled, true, "While element is being created, element should be added to the current element callback queue.");
+    runNextTest();
   };
 
   p.attributeChangedCallback = function(name, oldValue, newValue) {
     is(createdCallbackCalled, true, "attributeChanged callback should be called after the created callback because it was enqueued during created callback.");
     is(attributeChangedCallbackCalled, false, "attributeChanged callback should only be called once in this tests.");
     is(newValue, "bar", "The new value should be 'bar'");
     attributeChangedCallbackCalled = true;
-    runNextTest();
   };
 
   document.registerElement("x-one", { prototype: p });
   document.createElement("x-one");
 }
 
 function testChangeAttributeInEnteredViewCallback() {
   var p = Object.create(HTMLElement.prototype);
--- a/dom/webidl/CanvasRenderingContext2D.webidl
+++ b/dom/webidl/CanvasRenderingContext2D.webidl
@@ -22,16 +22,19 @@ dictionary ContextAttributes2D {
 
 dictionary HitRegionOptions {
   Path2D? path = null;
   DOMString id = "";
   Element? control = null;
 };
 
 typedef (HTMLImageElement or
+         SVGImageElement) HTMLOrSVGImageElement;
+
+typedef (HTMLOrSVGImageElement or
          HTMLCanvasElement or
          HTMLVideoElement or
          ImageBitmap) CanvasImageSource;
 
 interface CanvasRenderingContext2D {
 
   // back-reference to the canvas.  Might be null if we're not
   // associated with a canvas.
--- a/dom/webidl/ShadowRoot.webidl
+++ b/dom/webidl/ShadowRoot.webidl
@@ -12,16 +12,16 @@
 
 [Func="nsDocument::IsWebComponentsEnabled"]
 interface ShadowRoot : DocumentFragment
 {
   Element? getElementById(DOMString elementId);
   HTMLCollection getElementsByTagName(DOMString localName);
   HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
   HTMLCollection getElementsByClassName(DOMString classNames);
-  [SetterThrows,TreatNullAs=EmptyString]
+  [CEReactions, SetterThrows, TreatNullAs=EmptyString]
   attribute DOMString innerHTML;
   readonly attribute Element host;
   readonly attribute ShadowRoot? olderShadowRoot;
   attribute boolean applyAuthorStyles;
   readonly attribute StyleSheetList styleSheets;
 };
 
--- a/dom/xbl/nsXBLPrototypeHandler.cpp
+++ b/dom/xbl/nsXBLPrototypeHandler.cpp
@@ -153,18 +153,18 @@ nsXBLPrototypeHandler::TryConvertToKeybo
     eventType = KeyboardInput::KEY_PRESS;
   } else if (mEventName == nsGkAtoms::keyup) {
     eventType = KeyboardInput::KEY_UP;
   } else {
     return false;
   }
 
   // Convert the modifiers
-  Modifiers modifiersMask = GetModifiers();
-  Modifiers modifiers = GetModifiersMask();
+  Modifiers modifiersMask = GetModifiersMask();
+  Modifiers modifiers = GetModifiers();
 
   // Mask away any bits that won't be compared
   modifiers &= modifiersMask;
 
   // Convert the keyCode or charCode
   uint32_t keyCode;
   uint32_t charCode;
 
--- a/gfx/ipc/GraphicsMessages.ipdlh
+++ b/gfx/ipc/GraphicsMessages.ipdlh
@@ -16,16 +16,17 @@ namespace mozilla {
 namespace gfx {
 
 struct D3D11DeviceStatus
 {
   bool isWARP;
   bool textureSharingWorks;
   uint32_t featureLevel;
   DxgiAdapterDesc adapter;
+  int32_t sequenceNumber;
 };
 
 struct DevicePrefs
 {
   FeatureStatus hwCompositing;
   FeatureStatus d3d11Compositing;
   FeatureStatus oglCompositing;
   FeatureStatus advancedLayers;
--- a/gfx/layers/LayersLogging.cpp
+++ b/gfx/layers/LayersLogging.cpp
@@ -65,39 +65,39 @@ AppendToString(std::stringstream& aStrea
   aStream << pfx;
   aStream << nsPrintfCString(
     "(x=%d, y=%d, w=%d, h=%d)",
     r.x, r.y, r.width, r.height).get();
   aStream << sfx;
 }
 
 void
-AppendToString(std::stringstream& aStream, const WrColor& c,
+AppendToString(std::stringstream& aStream, const wr::ColorF& c,
                const char* pfx, const char* sfx)
 {
   aStream << pfx;
   aStream << nsPrintfCString(
     "rgba(%d, %d, %d, %f)",
     uint8_t(c.r*255.f), uint8_t(c.g*255.f), uint8_t(c.b*255.f), c.a).get();
   aStream << sfx;
 }
 
 void
-AppendToString(std::stringstream& aStream, const WrRect& r,
+AppendToString(std::stringstream& aStream, const wr::LayoutRect& r,
                const char* pfx, const char* sfx)
 {
   aStream << pfx;
   aStream << nsPrintfCString(
     "(x=%f, y=%f, w=%f, h=%f)",
-    r.x, r.y, r.width, r.height).get();
+    r.origin.x, r.origin.y, r.size.width, r.size.height).get();
   aStream << sfx;
 }
 
 void
-AppendToString(std::stringstream& aStream, const WrSize& s,
+AppendToString(std::stringstream& aStream, const wr::LayoutSize& s,
                const char* pfx, const char* sfx)
 {
   aStream << pfx;
   aStream << nsPrintfCString(
     "(w=%f, h=%f)",
     s.width, s.height).get();
   aStream << sfx;
 }
--- a/gfx/layers/LayersLogging.h
+++ b/gfx/layers/LayersLogging.h
@@ -13,21 +13,24 @@
 #include "mozilla/gfx/Types.h"          // for SamplingFilter, SurfaceFormat
 #include "mozilla/layers/CompositorTypes.h"  // for TextureFlags
 #include "mozilla/layers/WebRenderLayersLogging.h"
 #include "nsAString.h"
 #include "nsPrintfCString.h"            // for nsPrintfCString
 #include "nsRegion.h"                   // for nsRegion, nsIntRegion
 #include "nscore.h"                     // for nsACString, etc
 
-struct WrColor;
-struct WrRect;
-struct WrSize;
+namespace mozilla {
 
-namespace mozilla {
+namespace wr {
+struct ColorF;
+struct LayoutRect;
+struct LayoutSize;
+} // namespace wr
+
 namespace gfx {
 template <class units, class F> struct RectTyped;
 } // namespace gfx
 
 enum class ImageFormat;
 
 namespace layers {
 
@@ -87,25 +90,25 @@ AppendToString(std::stringstream& aStrea
   aStream << pfx;
   aStream << nsPrintfCString(
     "(x=%d, y=%d, w=%d, h=%d)",
     r.x, r.y, r.width, r.height).get();
   aStream << sfx;
 }
 
 void
-AppendToString(std::stringstream& aStream, const WrColor& c,
+AppendToString(std::stringstream& aStream, const wr::ColorF& c,
                const char* pfx="", const char* sfx="");
 
 void
-AppendToString(std::stringstream& aStream, const WrRect& r,
+AppendToString(std::stringstream& aStream, const wr::LayoutRect& r,
                const char* pfx="", const char* sfx="");
 
 void
-AppendToString(std::stringstream& aStream, const WrSize& s,
+AppendToString(std::stringstream& aStream, const wr::LayoutSize& s,
                const char* pfx="", const char* sfx="");
 
 void
 AppendToString(std::stringstream& aStream, const nsRegion& r,
                const char* pfx="", const char* sfx="");
 
 void
 AppendToString(std::stringstream& aStream, const nsIntRegion& r,
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -442,33 +442,33 @@ APZCTreeManager::UpdateHitTestingTree(ui
   WebRenderScrollDataWrapper wrapper(&aScrollData);
   UpdateHitTestingTreeImpl(aRootLayerTreeId, wrapper, aIsFirstPaint,
                            aOriginatingLayersId, aPaintSequenceNumber);
 }
 
 bool
 APZCTreeManager::PushStateToWR(wr::WebRenderAPI* aWrApi,
                                const TimeStamp& aSampleTime,
-                               nsTArray<WrTransformProperty>& aTransformArray)
+                               nsTArray<wr::WrTransformProperty>& aTransformArray)
 {
   APZThreadUtils::AssertOnCompositorThread();
   MOZ_ASSERT(aWrApi);
 
   MutexAutoLock lock(mTreeLock);
 
   // During the first pass through the tree, we build a cache of guid->HTTN so
   // that we can find the relevant APZC instances quickly in subsequent passes,
   // such as the one below to generate scrollbar transforms. Without this, perf
   // could end up being O(n^2) instead of O(n log n) because we'd have to search
   // the tree to find the corresponding APZC every time we hit a thumb node.
   std::unordered_map<ScrollableLayerGuid, HitTestingTreeNode*, ScrollableLayerGuidHash> httnMap;
 
   bool activeAnimations = false;
   uint64_t lastLayersId = -1;
-  WrPipelineId lastPipelineId;
+  wr::WrPipelineId lastPipelineId;
 
   // We iterate backwards here because the HitTestingTreeNode is optimized
   // for backwards iteration. The equivalent code in AsyncCompositionManager
   // iterates forwards, but the direction shouldn't really matter in practice
   // so we do what's faster. In the future, if we need to start doing the
   // equivalent of AlignFixedAndStickyLayers here, then the order will become
   // important and we'll need to take that into consideration.
   ForEachNode<ReverseIterator>(mRootNode.get(),
@@ -502,17 +502,17 @@ APZCTreeManager::PushStateToWR(wr::WebRe
         ParentLayerPoint layerTranslation = apzc->GetCurrentAsyncTransform(
             AsyncPanZoomController::eForCompositing).mTranslation;
         // The positive translation means the painted content is supposed to
         // move down (or to the right), and that corresponds to a reduction in
         // the scroll offset. Since we are effectively giving WR the async
         // scroll delta here, we want to negate the translation.
         ParentLayerPoint asyncScrollDelta = -layerTranslation;
         aWrApi->UpdateScrollPosition(lastPipelineId, apzc->GetGuid().mScrollId,
-            wr::ToWrPoint(asyncScrollDelta));
+            wr::ToLayoutPoint(asyncScrollDelta));
 
         apzc->ReportCheckerboard(aSampleTime);
         activeAnimations |= apzc->AdvanceAnimations(aSampleTime);
       });
 
   // Now we iterate over the nodes again, and generate the transforms needed
   // for scrollbar thumbs. Although we *could* do this as part of the previous
   // iteration, it's cleaner and more efficient to do it as a separate pass
--- a/gfx/layers/apz/src/APZCTreeManager.h
+++ b/gfx/layers/apz/src/APZCTreeManager.h
@@ -20,23 +20,22 @@
 #include "mozilla/RefPtr.h"             // for RefPtr
 #include "mozilla/TimeStamp.h"          // for mozilla::TimeStamp
 #include "nsCOMPtr.h"                   // for already_AddRefed
 
 #if defined(MOZ_WIDGET_ANDROID)
 #include "mozilla/layers/AndroidDynamicToolbarAnimator.h"
 #endif // defined(MOZ_WIDGET_ANDROID)
 
-struct WrTransformProperty;
-
 namespace mozilla {
 class MultiTouchInput;
 
 namespace wr {
 class WebRenderAPI;
+struct WrTransformProperty;
 }
 
 namespace layers {
 
 class Layer;
 class AsyncPanZoomController;
 class APZCTreeManagerParent;
 class CompositorBridgeParent;
@@ -174,17 +173,17 @@ public:
    * code in AsyncCompositionManager. If scrollbar transforms need updating
    * to reflect the async scroll position, the updated transforms are appended
    * to the provided aTransformArray.
    * Returns true if any APZ animations are in progress and we need to keep
    * compositing.
    */
   bool PushStateToWR(wr::WebRenderAPI* aWrApi,
                      const TimeStamp& aSampleTime,
-                     nsTArray<WrTransformProperty>& aTransformArray);
+                     nsTArray<wr::WrTransformProperty>& aTransformArray);
 
   /**
    * Walk the tree of APZCs and flushes the repaint requests for all the APZCS
    * corresponding to the given layers id. Finally, sends a flush complete
    * notification to the GeckoContentController for the layers id.
    */
   void FlushApzRepaints(uint64_t aLayersId);
 
--- a/gfx/layers/apz/src/FocusTarget.cpp
+++ b/gfx/layers/apz/src/FocusTarget.cpp
@@ -89,35 +89,51 @@ FocusTarget::FocusTarget(nsIPresShell* a
   : mSequenceNumber(aFocusSequenceNumber)
   , mFocusHasKeyEventListeners(false)
 {
   MOZ_ASSERT(aRootPresShell);
   MOZ_ASSERT(NS_IsMainThread());
 
   // Key events can be retargeted to a child PresShell when there is an iframe
   nsCOMPtr<nsIPresShell> presShell = GetRetargetEventPresShell(aRootPresShell);
+  nsCOMPtr<nsIDocument> document = presShell->GetDocument();
 
-  if (!presShell) {
+  if (!presShell || !document) {
     FT_LOG("Creating nil target with seq=%" PRIu64 " (can't find retargeted presshell)\n",
            aFocusSequenceNumber);
 
     mType = FocusTarget::eNone;
     return;
   }
 
-  // Get the content that should be scrolled for this PresShell, which is
-  // the current focused element or the current DOM selection
-  nsCOMPtr<nsIContent> scrollTarget = presShell->GetContentForScrolling();
+  // Find the focused content and use it to determine whether there are key event
+  // listeners or whether key events will be targeted at a different process
+  // through a remote browser.
+  nsCOMPtr<nsIContent> focusedContent = presShell->GetFocusedContentInOurWindow();
+
+  // Check if there are key event listeners that could prevent default or change
+  // the focus or selection of the page.
+  mFocusHasKeyEventListeners =
+    HasListenersForKeyEvents(focusedContent ? focusedContent.get()
+                                            : document->GetUnfocusedKeyEventTarget());
 
-  // Collect event listener information so we can track what is potentially focus
-  // changing
-  mFocusHasKeyEventListeners = HasListenersForKeyEvents(scrollTarget);
+  // Check if the focused element is content editable or if the document
+  // is in design mode.
+  if (IsEditableNode(focusedContent) ||
+      IsEditableNode(document)) {
+    FT_LOG("Creating nil target with seq=%" PRIu64 ", kl=%d (disabling for editable node)\n",
+           aFocusSequenceNumber,
+           static_cast<int>(mFocusHasKeyEventListeners));
 
-  // Check if the scroll target is a remote browser
-  if (TabParent* browserParent = TabParent::GetFrom(scrollTarget)) {
+    mType = FocusTarget::eNone;
+    return;
+  }
+
+  // Check if the focused element is a remote browser
+  if (TabParent* browserParent = TabParent::GetFrom(focusedContent)) {
     RenderFrameParent* rfp = browserParent->GetRenderFrame();
 
     // The globally focused element for scrolling is in a remote layer tree
     if (rfp) {
       FT_LOG("Creating reflayer target with seq=%" PRIu64 ", kl=%d, lt=%" PRIu64 "\n",
              aFocusSequenceNumber,
              mFocusHasKeyEventListeners,
              rfp->GetLayersId());
@@ -130,34 +146,39 @@ FocusTarget::FocusTarget(nsIPresShell* a
     FT_LOG("Creating nil target with seq=%" PRIu64 ", kl=%d (remote browser missing layers id)\n",
            aFocusSequenceNumber,
            mFocusHasKeyEventListeners);
 
     mType = FocusTarget::eNone;
     return;
   }
 
-  // If the focus isn't on a remote browser then check for scrollable targets
-  if (IsEditableNode(scrollTarget) ||
-      IsEditableNode(presShell->GetDocument())) {
-    FT_LOG("Creating nil target with seq=%" PRIu64 ", kl=%d (disabling for editable node)\n",
-           aFocusSequenceNumber,
-           mFocusHasKeyEventListeners);
+  // The content to scroll is either the focused element or the focus node of
+  // the selection. It's difficult to determine if an element is an interactive
+  // element requiring async keyboard scrolling to be disabled. So we only
+  // allow async key scrolling based on the selection, which doesn't have
+  // this problem and is more common.
+  if (focusedContent) {
+    FT_LOG("Creating nil target with seq=%" PRIu64 ", kl=%d (disabling for focusing an element)\n",
+           mFocusHasKeyEventListeners,
+           aFocusSequenceNumber);
 
     mType = FocusTarget::eNone;
     return;
   }
 
+  nsCOMPtr<nsIContent> selectedContent = presShell->GetSelectedContentForScrolling();
+
   // Gather the scrollable frames that would be scrolled in each direction
   // for this scroll target
   nsIScrollableFrame* horizontal =
-    presShell->GetScrollableFrameToScrollForContent(scrollTarget.get(),
+    presShell->GetScrollableFrameToScrollForContent(selectedContent.get(),
                                                     nsIPresShell::eHorizontal);
   nsIScrollableFrame* vertical =
-    presShell->GetScrollableFrameToScrollForContent(scrollTarget.get(),
+    presShell->GetScrollableFrameToScrollForContent(selectedContent.get(),
                                                     nsIPresShell::eVertical);
 
   // We might have the globally focused element for scrolling. Gather a ViewID for
   // the horizontal and vertical scroll targets of this element.
   mType = FocusTarget::eScrollLayer;
   mData.mScrollTargets.mHorizontal =
     nsLayoutUtils::FindIDForScrollableFrame(horizontal);
   mData.mScrollTargets.mVertical =
--- a/gfx/layers/client/ClientLayerManager.cpp
+++ b/gfx/layers/client/ClientLayerManager.cpp
@@ -511,17 +511,19 @@ ClientLayerManager::DidComposite(uint64_
     nsIWidgetListener *listener = mWidget->GetWidgetListener();
     if (listener) {
       listener->DidCompositeWindow(aTransactionId, aCompositeStart, aCompositeEnd);
     }
     listener = mWidget->GetAttachedWidgetListener();
     if (listener) {
       listener->DidCompositeWindow(aTransactionId, aCompositeStart, aCompositeEnd);
     }
-    mTransactionIdAllocator->NotifyTransactionCompleted(aTransactionId);
+    if (mTransactionIdAllocator) {
+      mTransactionIdAllocator->NotifyTransactionCompleted(aTransactionId);
+    }
   }
 
   // These observers fire whether or not we were in a transaction.
   for (size_t i = 0; i < mDidCompositeObservers.Length(); i++) {
     mDidCompositeObservers[i]->DidComposite();
   }
 }
 
--- a/gfx/layers/composite/GPUVideoTextureHost.cpp
+++ b/gfx/layers/composite/GPUVideoTextureHost.cpp
@@ -128,18 +128,18 @@ GPUVideoTextureHost::AddWRImage(wr::WebR
 {
   MOZ_ASSERT(mWrappedTextureHost);
 
   mWrappedTextureHost->AddWRImage(aAPI, aImageKeys, aExtID);
 }
 
 void
 GPUVideoTextureHost::PushExternalImage(wr::DisplayListBuilder& aBuilder,
-                                       const WrRect& aBounds,
-                                       const WrRect& aClip,
+                                       const wr::LayoutRect& aBounds,
+                                       const wr::LayoutRect& aClip,
                                        wr::ImageRendering aFilter,
                                        Range<const wr::ImageKey>& aImageKeys)
 {
   MOZ_ASSERT(mWrappedTextureHost);
   MOZ_ASSERT(aImageKeys.length() > 0);
 
   mWrappedTextureHost->PushExternalImage(aBuilder,
                                          aBounds,
--- a/gfx/layers/composite/GPUVideoTextureHost.h
+++ b/gfx/layers/composite/GPUVideoTextureHost.h
@@ -51,18 +51,18 @@ public:
   virtual void GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
                               const std::function<wr::ImageKey()>& aImageKeyAllocator) override;
 
   virtual void AddWRImage(wr::WebRenderAPI* aAPI,
                           Range<const wr::ImageKey>& aImageKeys,
                           const wr::ExternalImageId& aExtID) override;
 
   virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder,
-                                 const WrRect& aBounds,
-                                 const WrRect& aClip,
+                                 const wr::LayoutRect& aBounds,
+                                 const wr::LayoutRect& aClip,
                                  wr::ImageRendering aFilter,
                                  Range<const wr::ImageKey>& aImageKeys) override;
 
 protected:
   RefPtr<TextureHost> mWrappedTextureHost;
 };
 
 } // namespace layers
--- a/gfx/layers/composite/TextureHost.cpp
+++ b/gfx/layers/composite/TextureHost.cpp
@@ -602,49 +602,49 @@ BufferTextureHost::AddWRImage(wr::WebRen
     MOZ_ASSERT(aImageKeys.length() == 3);
 
     const layers::YCbCrDescriptor& desc = mDescriptor.get_YCbCrDescriptor();
     wr::ImageDescriptor yDescriptor(desc.ySize(), desc.ySize().width, gfx::SurfaceFormat::A8);
     wr::ImageDescriptor cbcrDescriptor(desc.cbCrSize(), desc.cbCrSize().width, gfx::SurfaceFormat::A8);
     aAPI->AddExternalImage(aImageKeys[0],
                            yDescriptor,
                            aExtID,
-                           WrExternalImageBufferType::ExternalBuffer,
+                           wr::WrExternalImageBufferType::ExternalBuffer,
                            0);
     aAPI->AddExternalImage(aImageKeys[1],
                            cbcrDescriptor,
                            aExtID,
-                           WrExternalImageBufferType::ExternalBuffer,
+                           wr::WrExternalImageBufferType::ExternalBuffer,
                            1);
     aAPI->AddExternalImage(aImageKeys[2],
                            cbcrDescriptor,
                            aExtID,
-                           WrExternalImageBufferType::ExternalBuffer,
+                           wr::WrExternalImageBufferType::ExternalBuffer,
                            2);
   }
 }
 
 void
 BufferTextureHost::PushExternalImage(wr::DisplayListBuilder& aBuilder,
-                                     const WrRect& aBounds,
-                                     const WrRect& aClip,
+                                     const wr::LayoutRect& aBounds,
+                                     const wr::LayoutRect& aClip,
                                      wr::ImageRendering aFilter,
                                      Range<const wr::ImageKey>& aImageKeys)
 {
   if (GetFormat() != gfx::SurfaceFormat::YUV) {
     MOZ_ASSERT(aImageKeys.length() == 1);
     aBuilder.PushImage(aBounds, aClip, aFilter, aImageKeys[0]);
   } else {
     MOZ_ASSERT(aImageKeys.length() == 3);
     aBuilder.PushYCbCrPlanarImage(aBounds,
                                   aClip,
                                   aImageKeys[0],
                                   aImageKeys[1],
                                   aImageKeys[2],
-                                  WrYuvColorSpace::Rec601,
+                                  wr::WrYuvColorSpace::Rec601,
                                   aFilter);
   }
 }
 
 void
 TextureHost::DeserializeReadLock(const ReadLockDescriptor& aDesc,
                                  ISurfaceAllocator* aAllocator)
 {
--- a/gfx/layers/composite/TextureHost.h
+++ b/gfx/layers/composite/TextureHost.h
@@ -638,18 +638,18 @@ public:
                           Range<const wr::ImageKey>& aImageKeys,
                           const wr::ExternalImageId& aExtID)
   {
     MOZ_ASSERT_UNREACHABLE("No AddWRImage() implementation for this TextureHost type.");
   }
 
   // Put all necessary WR commands into DisplayListBuilder for this textureHost rendering.
   virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder,
-                                 const WrRect& aBounds,
-                                 const WrRect& aClip,
+                                 const wr::LayoutRect& aBounds,
+                                 const wr::LayoutRect& aClip,
                                  wr::ImageRendering aFilter,
                                  Range<const wr::ImageKey>& aKeys)
   {
     MOZ_ASSERT_UNREACHABLE("No PushExternalImage() implementation for this TextureHost type.");
   }
 
 protected:
   void ReadUnlock();
@@ -744,18 +744,18 @@ public:
   virtual void GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
                               const std::function<wr::ImageKey()>& aImageKeyAllocator) override;
 
   virtual void AddWRImage(wr::WebRenderAPI* aAPI,
                           Range<const wr::ImageKey>& aImageKeys,
                           const wr::ExternalImageId& aExtID) override;
 
   virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder,
-                                 const WrRect& aBounds,
-                                 const WrRect& aClip,
+                                 const wr::LayoutRect& aBounds,
+                                 const wr::LayoutRect& aClip,
                                  wr::ImageRendering aFilter,
                                  Range<const wr::ImageKey>& aImageKeys) override;
 
 protected:
   bool Upload(nsIntRegion *aRegion = nullptr);
   bool UploadIfNeeded();
   bool MaybeUpload(nsIntRegion *aRegion);
   bool EnsureWrappingTextureSource();
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -979,18 +979,18 @@ DXGITextureHostD3D11::AddWRImage(wr::Web
                                  Range<const wr::ImageKey>& aImageKeys,
                                  const wr::ExternalImageId& aExtID)
 {
   MOZ_ASSERT_UNREACHABLE("No AddWRImage() implementation for this DXGITextureHostD3D11 type.");
 }
 
 void
 DXGITextureHostD3D11::PushExternalImage(wr::DisplayListBuilder& aBuilder,
-                                        const WrRect& aBounds,
-                                        const WrRect& aClip,
+                                        const wr::LayoutRect& aBounds,
+                                        const wr::LayoutRect& aClip,
                                         wr::ImageRendering aFilter,
                                         Range<const wr::ImageKey>& aImageKeys)
 {
   MOZ_ASSERT_UNREACHABLE("No PushExternalImage() implementation for this DXGITextureHostD3D11 type.");
 }
 
 DXGIYCbCrTextureHostD3D11::DXGIYCbCrTextureHostD3D11(TextureFlags aFlags,
   const SurfaceDescriptorDXGIYCbCr& aDescriptor)
@@ -1146,18 +1146,18 @@ DXGIYCbCrTextureHostD3D11::AddWRImage(wr
                                       Range<const wr::ImageKey>& aImageKeys,
                                       const wr::ExternalImageId& aExtID)
 {
   MOZ_ASSERT_UNREACHABLE("No AddWRImage() implementation for this DXGIYCbCrTextureHostD3D11 type.");
 }
 
 void
 DXGIYCbCrTextureHostD3D11::PushExternalImage(wr::DisplayListBuilder& aBuilder,
-                                             const WrRect& aBounds,
-                                             const WrRect& aClip,
+                                             const wr::LayoutRect& aBounds,
+                                             const wr::LayoutRect& aClip,
                                              wr::ImageRendering aFilter,
                                              Range<const wr::ImageKey>& aImageKeys)
 {
   MOZ_ASSERT_UNREACHABLE("No PushExternalImage() implementation for this DXGIYCbCrTextureHostD3D11 type.");
 }
 
 bool
 DXGIYCbCrTextureHostD3D11::AcquireTextureSource(CompositableTextureSourceRef& aTexture)
--- a/gfx/layers/d3d11/TextureD3D11.h
+++ b/gfx/layers/d3d11/TextureD3D11.h
@@ -326,18 +326,18 @@ public:
   virtual void GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
                               const std::function<wr::ImageKey()>& aImageKeyAllocator) override;
 
   virtual void AddWRImage(wr::WebRenderAPI* aAPI,
                           Range<const wr::ImageKey>& aImageKeys,
                           const wr::ExternalImageId& aExtID) override;
 
   virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder,
-                                 const WrRect& aBounds,
-                                 const WrRect& aClip,
+                                 const wr::LayoutRect& aBounds,
+                                 const wr::LayoutRect& aClip,
                                  wr::ImageRendering aFilter,
                                  Range<const wr::ImageKey>& aImageKeys) override;
 
 protected:
   bool LockInternal();
   void UnlockInternal();
 
   bool EnsureTextureSource();
@@ -387,18 +387,18 @@ public:
   virtual void GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
                               const std::function<wr::ImageKey()>& aImageKeyAllocator) override;
 
   virtual void AddWRImage(wr::WebRenderAPI* aAPI,
                           Range<const wr::ImageKey>& aImageKeys,
                           const wr::ExternalImageId& aExtID) override;
 
   virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder,
-                                 const WrRect& aBounds,
-                                 const WrRect& aClip,
+                                 const wr::LayoutRect& aBounds,
+                                 const wr::LayoutRect& aClip,
                                  wr::ImageRendering aFilter,
                                  Range<const wr::ImageKey>& aImageKeys) override;
 
 private:
   bool EnsureTextureSource();
 
 protected:
   RefPtr<ID3D11Device> GetDevice();
--- a/gfx/layers/ipc/CompositorBridgeParent.h
+++ b/gfx/layers/ipc/CompositorBridgeParent.h
@@ -208,16 +208,18 @@ public:
   virtual mozilla::ipc::IPCResult RecvFlushRenderingAsync() override;
   virtual mozilla::ipc::IPCResult RecvWaitOnTransactionProcessed() override;
   virtual mozilla::ipc::IPCResult RecvForcePresent() override;
 
   virtual mozilla::ipc::IPCResult RecvNotifyRegionInvalidated(const nsIntRegion& aRegion) override;
   virtual mozilla::ipc::IPCResult RecvStartFrameTimeRecording(const int32_t& aBufferSize, uint32_t* aOutStartIndex) override;
   virtual mozilla::ipc::IPCResult RecvStopFrameTimeRecording(const uint32_t& aStartIndex, InfallibleTArray<float>* intervals) override;
 
+  virtual mozilla::ipc::IPCResult RecvCheckContentOnlyTDR(const uint32_t& sequenceNum, bool* isContentOnlyTDR) override { return IPC_OK(); }
+
   // Unused for chrome <-> compositor communication (which this class does).
   // @see CrossProcessCompositorBridgeParent::RecvRequestNotifyAfterRemotePaint
   virtual mozilla::ipc::IPCResult RecvRequestNotifyAfterRemotePaint() override { return IPC_OK(); };
 
   virtual mozilla::ipc::IPCResult RecvClearApproximatelyVisibleRegions(const uint64_t& aLayersId,
                                                                        const uint32_t& aPresShellId) override;
   void ClearApproximatelyVisibleRegions(const uint64_t& aLayersId,
                                         const Maybe<uint32_t>& aPresShellId);
--- a/gfx/layers/ipc/CrossProcessCompositorBridgeParent.cpp
+++ b/gfx/layers/ipc/CrossProcessCompositorBridgeParent.cpp
@@ -5,16 +5,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/layers/CrossProcessCompositorBridgeParent.h"
 #include <stdint.h>                     // for uint64_t
 #include "LayerTransactionParent.h"     // for LayerTransactionParent
 #include "base/message_loop.h"          // for MessageLoop
 #include "base/task.h"                  // for CancelableTask, etc
 #include "base/thread.h"                // for Thread
+#ifdef XP_WIN
+#include "mozilla/gfx/DeviceManagerDx.h"// for DeviceManagerDx
+#endif
 #include "mozilla/ipc/Transport.h"      // for Transport
 #include "mozilla/layers/AnimationHelper.h" // for CompositorAnimationStorage
 #include "mozilla/layers/APZCTreeManager.h"  // for APZCTreeManager
 #include "mozilla/layers/APZCTreeManagerParent.h"  // for APZCTreeManagerParent
 #include "mozilla/layers/APZThreadUtils.h"  // for APZCTreeManager
 #include "mozilla/layers/AsyncCompositionManager.h"
 #include "mozilla/layers/CompositorOptions.h"
 #include "mozilla/layers/CompositorThread.h"
@@ -271,16 +274,39 @@ CrossProcessCompositorBridgeParent::Recv
                                                                  const base::ProcessId& pid,
                                                                  CompositorOptions* aOptions)
 {
   // This can only be called from the browser process, as the mapping
   // ensures proper window ownership of layer trees.
   return IPC_FAIL_NO_REASON(this);
 }
 
+
+mozilla::ipc::IPCResult
+CrossProcessCompositorBridgeParent::RecvCheckContentOnlyTDR(const uint32_t& sequenceNum,
+                                                            bool* isContentOnlyTDR)
+{
+  *isContentOnlyTDR = false;
+#ifdef XP_WIN
+  ContentDeviceData compositor;
+
+  DeviceManagerDx* dm = DeviceManagerDx::Get();
+
+  // Check that the D3D11 device sequence numbers match.
+  D3D11DeviceStatus status;
+  dm->ExportDeviceInfo(&status);
+
+  if (sequenceNum == status.sequenceNumber() && !dm->HasDeviceReset()) {
+    *isContentOnlyTDR = true;
+  }
+
+#endif
+  return IPC_OK();
+};
+
 void
 CrossProcessCompositorBridgeParent::ShadowLayersUpdated(
   LayerTransactionParent* aLayerTree,
   const TransactionInfo& aInfo,
   bool aHitTestUpdate)
 {
   uint64_t id = aLayerTree->GetId();
 
--- a/gfx/layers/ipc/CrossProcessCompositorBridgeParent.h
+++ b/gfx/layers/ipc/CrossProcessCompositorBridgeParent.h
@@ -53,16 +53,18 @@ public:
   virtual mozilla::ipc::IPCResult RecvFlushRendering() override { return IPC_OK(); }
   virtual mozilla::ipc::IPCResult RecvFlushRenderingAsync() override { return IPC_OK(); }
   virtual mozilla::ipc::IPCResult RecvForcePresent() override { return IPC_OK(); }
   virtual mozilla::ipc::IPCResult RecvWaitOnTransactionProcessed() override { return IPC_OK(); }
   virtual mozilla::ipc::IPCResult RecvNotifyRegionInvalidated(const nsIntRegion& aRegion) override { return IPC_OK(); }
   virtual mozilla::ipc::IPCResult RecvStartFrameTimeRecording(const int32_t& aBufferSize, uint32_t* aOutStartIndex) override { return IPC_OK(); }
   virtual mozilla::ipc::IPCResult RecvStopFrameTimeRecording(const uint32_t& aStartIndex, InfallibleTArray<float>* intervals) override  { return IPC_OK(); }
 
+  virtual mozilla::ipc::IPCResult RecvCheckContentOnlyTDR(const uint32_t& sequenceNum, bool* isContentOnlyTDR) override;
+
   virtual mozilla::ipc::IPCResult RecvClearApproximatelyVisibleRegions(const uint64_t& aLayersId,
                                                     const uint32_t& aPresShellId) override;
 
   virtual mozilla::ipc::IPCResult RecvNotifyApproximatelyVisibleRegion(const ScrollableLayerGuid& aGuid,
                                                     const CSSIntRegion& aRegion) override;
 
   virtual mozilla::ipc::IPCResult RecvAllPluginsCaptured() override { return IPC_OK(); }
 
--- a/gfx/layers/ipc/PCompositorBridge.ipdl
+++ b/gfx/layers/ipc/PCompositorBridge.ipdl
@@ -247,16 +247,19 @@ parent:
   async PTexture(SurfaceDescriptor aSharedData, LayersBackend aBackend, TextureFlags aTextureFlags, uint64_t id, uint64_t aSerial, MaybeExternalImageId aExternalImageId);
 
   sync SyncWithCompositor();
 
   // The pipelineId is the same as the layersId
   sync PWebRenderBridge(PipelineId pipelineId, LayoutDeviceIntSize aSize)
     returns (TextureFactoryIdentifier textureFactoryIdentifier, uint32_t idNamespace); //XXX: use the WrIdNamespace type
 
+  sync CheckContentOnlyTDR(uint32_t sequenceNum)
+    returns (bool isContentOnlyTDR);
+
 child:
   // Send back Compositor Frame Metrics from APZCs so tiled layers can
   // update progressively.
   async SharedCompositorFrameMetrics(Handle metrics, CrossProcessMutexHandle mutex, uint64_t aLayersId, uint32_t aAPZCId);
   async ReleaseSharedCompositorFrameMetrics(ViewID aId, uint32_t aAPZCId);
 };
 
 } // layers
--- a/gfx/layers/ipc/PWebRenderBridge.ipdl
+++ b/gfx/layers/ipc/PWebRenderBridge.ipdl
@@ -18,17 +18,17 @@ using mozilla::layers::APZTestData from 
 using struct mozilla::layers::ScrollableLayerGuid from "FrameMetrics.h";
 using struct mozilla::layers::TextureInfo from "mozilla/layers/CompositorTypes.h";
 using mozilla::layers::CompositableHandle from "mozilla/layers/LayersTypes.h";
 using mozilla::wr::ByteBuffer from "mozilla/webrender/WebRenderTypes.h";
 using mozilla::wr::ExternalImageId from "mozilla/webrender/WebRenderTypes.h";
 using mozilla::wr::ImageKey from "mozilla/webrender/WebRenderTypes.h";
 using mozilla::wr::FontKey from "mozilla/webrender/WebRenderTypes.h";
 using mozilla::wr::PipelineId from "mozilla/webrender/WebRenderTypes.h";
-using WrBuiltDisplayListDescriptor from "mozilla/webrender/webrender_ffi.h";
+using mozilla::wr::BuiltDisplayListDescriptor from "mozilla/webrender/webrender_ffi.h";
 using mozilla::layers::WebRenderScrollData from "mozilla/layers/WebRenderScrollData.h";
 
 namespace mozilla {
 namespace layers {
 
 sync protocol PWebRenderBridge
 {
   manager PCompositorBridge;
@@ -50,20 +50,20 @@ parent:
   async UpdateImage(ImageKey aImageKey, IntSize aSize,
                    SurfaceFormat aFormat, ByteBuffer aBytes);
   async DeleteImage(ImageKey aImageKey);
   async DeleteCompositorAnimations(uint64_t[] aIds);
   async AddRawFont(FontKey aFontKey, ByteBuffer aBytes, uint32_t aFontIndex);
   async DeleteFont(FontKey aFontKey);
   async DPBegin(IntSize aSize);
   async DPEnd(IntSize aSize, WebRenderParentCommand[] commands, OpDestroy[] toDestroy, uint64_t fwdTransactionId, uint64_t transactionId,
-              WrSize aContentSize, ByteBuffer aDL, WrBuiltDisplayListDescriptor aDLDesc,
+              LayoutSize aContentSize, ByteBuffer aDL, BuiltDisplayListDescriptor aDLDesc,
               WebRenderScrollData aScrollData, uint32_t idNameSpace);
   sync DPSyncEnd(IntSize aSize, WebRenderParentCommand[] commands, OpDestroy[] toDestroy, uint64_t fwdTransactionId, uint64_t transactionId,
-                 WrSize aContentSize, ByteBuffer aDL, WrBuiltDisplayListDescriptor aDLDesc,
+                 LayoutSize aContentSize, ByteBuffer aDL, BuiltDisplayListDescriptor aDLDesc,
                  WebRenderScrollData aScrollData, uint32_t idNameSpace);
   async ParentCommands(WebRenderParentCommand[] commands);
   sync DPGetSnapshot(PTexture texture);
   async AddPipelineIdForAsyncCompositable(PipelineId aImageId, CompositableHandle aHandle);
   async RemovePipelineIdForAsyncCompositable(PipelineId aPipelineId);
   async AddExternalImageIdForCompositable(ExternalImageId aImageId, CompositableHandle aHandle);
   async RemoveExternalImageId(ExternalImageId aImageId);
   async SetLayerObserverEpoch(uint64_t layerObserverEpoch);
--- a/gfx/layers/ipc/WebRenderMessages.ipdlh
+++ b/gfx/layers/ipc/WebRenderMessages.ipdlh
@@ -4,20 +4,20 @@
 /* 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 LayersSurfaces;
 include LayersMessages;
 include protocol PTexture;
 
-using WrSize from "mozilla/webrender/webrender_ffi.h";
-using WrImageRendering from "mozilla/webrender/webrender_ffi.h";
-using WrMixBlendMode from "mozilla/webrender/webrender_ffi.h";
-using MaybeImageMask from "mozilla/webrender/WebRenderTypes.h";
+using mozilla::wr::LayoutSize from "mozilla/webrender/webrender_ffi.h";
+using mozilla::wr::ImageRendering from "mozilla/webrender/webrender_ffi.h";
+using mozilla::wr::MixBlendMode from "mozilla/webrender/webrender_ffi.h";
+using mozilla::wr::MaybeImageMask from "mozilla/webrender/WebRenderTypes.h";
 using mozilla::wr::ExternalImageId from "mozilla/webrender/WebRenderTypes.h";
 using mozilla::wr::ImageKey from "mozilla/webrender/WebRenderTypes.h";
 using mozilla::wr::PipelineId from "mozilla/webrender/WebRenderTypes.h";
 using mozilla::gfx::MaybeIntSize from "mozilla/gfx/Point.h";
 using mozilla::LayerPoint from "Units.h";
 using mozilla::layers::MaybeLayerRect from "mozilla/layers/LayersTypes.h";
 using class mozilla::gfx::Matrix4x4 from "mozilla/gfx/Matrix.h";
 using struct mozilla::void_t from "ipc/IPCMessageUtils.h";
@@ -46,18 +46,18 @@ struct OpAddCompositorAnimations {
   OptionalOpacity opacity;
 };
 
 struct OpUpdateAsyncImagePipeline {
   PipelineId pipelineId;
   LayerRect scBounds;
   Matrix4x4 scTransform;
   MaybeIntSize scaleToSize;
-  WrImageRendering filter;
-  WrMixBlendMode mixBlendMode;
+  ImageRendering filter;
+  MixBlendMode mixBlendMode;
 };
 
 union WebRenderParentCommand {
   OpAddExternalImage;
   OpUpdateAsyncImagePipeline;
   CompositableOperation;
   OpAddCompositorAnimations;
 };
--- a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
+++ b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
@@ -173,64 +173,64 @@ MacIOSurfaceTextureHostOGL::AddWRImage(w
     case gfx::SurfaceFormat::B8G8R8A8:
     case gfx::SurfaceFormat::B8G8R8X8: {
       MOZ_ASSERT(aImageKeys.length() == 1);
       MOZ_ASSERT(mSurface->GetPlaneCount() == 0);
       wr::ImageDescriptor descriptor(GetSize(), GetFormat());
       aAPI->AddExternalImage(aImageKeys[0],
                              descriptor,
                              aExtID,
-                             WrExternalImageBufferType::TextureRectHandle,
+                             wr::WrExternalImageBufferType::TextureRectHandle,
                              0);
       break;
     }
     case gfx::SurfaceFormat::YUV422: {
       // This is the special buffer format. The buffer contents could be a
       // converted RGB interleaving data or a YCbCr interleaving data depending
       // on the different platform setting. (e.g. It will be RGB at OpenGL 2.1
       // and YCbCr at OpenGL 3.1)
       MOZ_ASSERT(aImageKeys.length() == 1);
       MOZ_ASSERT(mSurface->GetPlaneCount() == 0);
       wr::ImageDescriptor descriptor(GetSize(), gfx::SurfaceFormat::R8G8B8X8);
       aAPI->AddExternalImage(aImageKeys[0],
                              descriptor,
                              aExtID,
-                             WrExternalImageBufferType::TextureRectHandle,
+                             wr::WrExternalImageBufferType::TextureRectHandle,
                              0);
       break;
     }
     case gfx::SurfaceFormat::NV12: {
       MOZ_ASSERT(aImageKeys.length() == 2);
       MOZ_ASSERT(mSurface->GetPlaneCount() == 2);
       wr::ImageDescriptor descriptor0(gfx::IntSize(mSurface->GetDevicePixelWidth(0), mSurface->GetDevicePixelHeight(0)),
                                       gfx::SurfaceFormat::A8);
       wr::ImageDescriptor descriptor1(gfx::IntSize(mSurface->GetDevicePixelWidth(1), mSurface->GetDevicePixelHeight(1)),
                                       gfx::SurfaceFormat::R8G8);
       aAPI->AddExternalImage(aImageKeys[0],
                              descriptor0,
                              aExtID,
-                             WrExternalImageBufferType::TextureRectHandle,
+                             wr::WrExternalImageBufferType::TextureRectHandle,
                              0);
       aAPI->AddExternalImage(aImageKeys[1],
                              descriptor1,
                              aExtID,
-                             WrExternalImageBufferType::TextureRectHandle,
+                             wr::WrExternalImageBufferType::TextureRectHandle,
                              1);
       break;
     }
     default: {
       MOZ_ASSERT_UNREACHABLE("unexpected to be called");
     }
   }
 }
 
 void
 MacIOSurfaceTextureHostOGL::PushExternalImage(wr::DisplayListBuilder& aBuilder,
-                                              const WrRect& aBounds,
-                                              const WrRect& aClip,
+                                              const wr::LayoutRect& aBounds,
+                                              const wr::LayoutRect& aClip,
                                               wr::ImageRendering aFilter,
                                               Range<const wr::ImageKey>& aImageKeys)
 {
   switch (GetFormat()) {
     case gfx::SurfaceFormat::R8G8B8X8:
     case gfx::SurfaceFormat::R8G8B8A8:
     case gfx::SurfaceFormat::B8G8R8A8:
     case gfx::SurfaceFormat::B8G8R8X8: {
@@ -240,28 +240,28 @@ MacIOSurfaceTextureHostOGL::PushExternal
       break;
     }
     case gfx::SurfaceFormat::YUV422: {
       MOZ_ASSERT(aImageKeys.length() == 1);
       MOZ_ASSERT(mSurface->GetPlaneCount() == 0);
       aBuilder.PushYCbCrInterleavedImage(aBounds,
                                          aClip,
                                          aImageKeys[0],
-                                         WrYuvColorSpace::Rec601,
+                                         wr::WrYuvColorSpace::Rec601,
                                          aFilter);
       break;
     }
     case gfx::SurfaceFormat::NV12: {
       MOZ_ASSERT(aImageKeys.length() == 2);
       MOZ_ASSERT(mSurface->GetPlaneCount() == 2);
       aBuilder.PushNV12Image(aBounds,
                              aClip,
                              aImageKeys[0],
                              aImageKeys[1],
-                             WrYuvColorSpace::Rec601,
+                             wr::WrYuvColorSpace::Rec601,
                              aFilter);
       break;
     }
     default: {
       MOZ_ASSERT_UNREACHABLE("unexpected to be called");
     }
   }
 }
--- a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h
+++ b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h
@@ -70,18 +70,18 @@ public:
   virtual void GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
                               const std::function<wr::ImageKey()>& aImageKeyAllocator) override;
 
   virtual void AddWRImage(wr::WebRenderAPI* aAPI,
                           Range<const wr::ImageKey>& aImageKeys,
                           const wr::ExternalImageId& aExtID) override;
 
   virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder,
-                                 const WrRect& aBounds,
-                                 const WrRect& aClip,
+                                 const wr::LayoutRect& aBounds,
+                                 const wr::LayoutRect& aClip,
                                  wr::ImageRendering aFilter,
                                  Range<const wr::ImageKey>& aImageKeys) override;
 
 protected:
   GLTextureSource* CreateTextureSourceForPlane(size_t aPlane);
 
   RefPtr<GLTextureSource> mTextureSource;
   RefPtr<MacIOSurface> mSurface;
--- a/gfx/layers/wr/ScrollingLayersHelper.cpp
+++ b/gfx/layers/wr/ScrollingLayersHelper.cpp
@@ -66,18 +66,18 @@ ScrollingLayersHelper::ScrollingLayersHe
     // However, when we get the scrollable rect from the FrameMetrics, the origin
     // has nothing to do with the position of the frame but instead represents
     // the minimum allowed scroll offset of the scrollable content. While APZ
     // uses this to clamp the scroll position, we don't need to send this to
     // WebRender at all. Instead, we take the position from the composition
     // bounds.
     contentRect.MoveTo(clipBounds.TopLeft());
     mBuilder->PushScrollLayer(fm.GetScrollId(),
-        aStackingContext.ToRelativeWrRect(contentRect),
-        aStackingContext.ToRelativeWrRect(clipBounds));
+        aStackingContext.ToRelativeLayoutRect(contentRect),
+        aStackingContext.ToRelativeLayoutRect(clipBounds));
   }
 
   // The scrolled clip on the layer is "inside" all of the scrollable metadatas
   // on that layer. That is, the clip scrolls along with the content in
   // child layers. So we need to apply this after pushing all the scroll layers,
   // which we do above.
   if (const Maybe<LayerClip>& scrolledClip = layer->GetScrolledClip()) {
     PushLayerClip(scrolledClip.ref(), aStackingContext);
@@ -115,38 +115,38 @@ ScrollingLayersHelper::PushLayerLocalCli
   if (const Maybe<ParentLayerIntRect>& rect = layer->GetClipRect()) {
     clip = Some(IntRectToRect(rect.ref()));
   } else if (layer->GetMaskLayer()) {
     // this layer has a mask, but no clip rect. so let's use the transformed
     // visible bounds as the clip rect.
     clip = Some(layer->GetLocalTransformTyped().TransformBounds(mLayer->Bounds()));
   }
   if (clip) {
-    Maybe<WrImageMask> mask = mLayer->BuildWrMaskLayer(aStackingContext);
+    Maybe<wr::WrImageMask> mask = mLayer->BuildWrMaskLayer(aStackingContext);
     LayerRect clipRect = ViewAs<LayerPixel>(clip.ref(),
         PixelCastJustification::MovingDownToChildren);
-    mBuilder->PushClip(aStackingContext.ToRelativeWrRect(clipRect), mask.ptrOr(nullptr));
+    mBuilder->PushClip(aStackingContext.ToRelativeLayoutRect(clipRect), mask.ptrOr(nullptr));
     mPushedLayerLocalClip = true;
   }
 }
 
 void
 ScrollingLayersHelper::PushLayerClip(const LayerClip& aClip,
                                      const StackingContextHelper& aSc)
 {
   LayerRect clipRect = IntRectToRect(ViewAs<LayerPixel>(aClip.GetClipRect(),
         PixelCastJustification::MovingDownToChildren));
-  Maybe<WrImageMask> mask;
+  Maybe<wr::WrImageMask> mask;
   if (Maybe<size_t> maskLayerIndex = aClip.GetMaskLayerIndex()) {
     Layer* maskLayer = mLayer->GetLayer()->GetAncestorMaskLayerAt(maskLayerIndex.value());
     WebRenderLayer* maskWrLayer = WebRenderLayer::ToWebRenderLayer(maskLayer);
     // TODO: check this transform is correct in all cases
     mask = maskWrLayer->RenderMaskLayer(aSc, maskLayer->GetTransform());
   }
-  mBuilder->PushClip(aSc.ToRelativeWrRect(clipRect), mask.ptrOr(nullptr));
+  mBuilder->PushClip(aSc.ToRelativeLayoutRect(clipRect), mask.ptrOr(nullptr));
 }
 
 ScrollingLayersHelper::~ScrollingLayersHelper()
 {
   Layer* layer = mLayer->GetLayer();
   if (!mLayer->WrManager()->AsyncPanZoomEnabled()) {
     if (mPushedLayerLocalClip) {
       mBuilder->PopClip();
--- a/gfx/layers/wr/StackingContextHelper.cpp
+++ b/gfx/layers/wr/StackingContextHelper.cpp
@@ -19,105 +19,105 @@ StackingContextHelper::StackingContextHe
 
 StackingContextHelper::StackingContextHelper(const StackingContextHelper& aParentSC,
                                              wr::DisplayListBuilder& aBuilder,
                                              LayerRect aBoundForSC,
                                              LayerPoint aOrigin,
                                              uint64_t aAnimationsId,
                                              float* aOpacityPtr,
                                              gfx::Matrix4x4* aTransformPtr,
-                                             const nsTArray<WrFilterOp>& aFilters)
+                                             const nsTArray<wr::WrFilterOp>& aFilters)
   : mBuilder(&aBuilder)
 {
-  WrRect scBounds = aParentSC.ToRelativeWrRect(aBoundForSC);
+  wr::LayoutRect scBounds = aParentSC.ToRelativeLayoutRect(aBoundForSC);
   if (aTransformPtr) {
     mTransform = *aTransformPtr;
   }
 
   mBuilder->PushStackingContext(scBounds,
                                 aAnimationsId,
                                 aOpacityPtr,
                                 aTransformPtr,
-                                WrTransformStyle::Flat,
+                                wr::TransformStyle::Flat,
                                 // TODO: set correct blend mode.
-                                wr::ToWrMixBlendMode(gfx::CompositionOp::OP_OVER),
+                                wr::ToMixBlendMode(gfx::CompositionOp::OP_OVER),
                                 aFilters);
 
   mOrigin = aOrigin;
 }
 
 StackingContextHelper::StackingContextHelper(const StackingContextHelper& aParentSC,
                                              wr::DisplayListBuilder& aBuilder,
                                              WebRenderLayer* aLayer,
                                              const Maybe<gfx::Matrix4x4>& aTransform,
-                                             const nsTArray<WrFilterOp>& aFilters)
+                                             const nsTArray<wr::WrFilterOp>& aFilters)
   : mBuilder(&aBuilder)
 {
-  WrRect scBounds = aParentSC.ToRelativeWrRect(aLayer->BoundsForStackingContext());
+  wr::LayoutRect scBounds = aParentSC.ToRelativeLayoutRect(aLayer->BoundsForStackingContext());
   Layer* layer = aLayer->GetLayer();
   mTransform = aTransform.valueOr(layer->GetTransform());
 
   float opacity = 1.0f;
   mBuilder->PushStackingContext(scBounds, 0, &opacity,
                                 mTransform.IsIdentity() ? nullptr : &mTransform,
-                                WrTransformStyle::Flat,
-                                wr::ToWrMixBlendMode(layer->GetMixBlendMode()),
+                                wr::TransformStyle::Flat,
+                                wr::ToMixBlendMode(layer->GetMixBlendMode()),
                                 aFilters);
   mOrigin = aLayer->Bounds().TopLeft();
 }
 
 StackingContextHelper::StackingContextHelper(const StackingContextHelper& aParentSC,
                                              wr::DisplayListBuilder& aBuilder,
                                              WebRenderLayer* aLayer,
                                              uint64_t aAnimationsId,
                                              float* aOpacityPtr,
                                              gfx::Matrix4x4* aTransformPtr,
-                                             const nsTArray<WrFilterOp>& aFilters)
+                                             const nsTArray<wr::WrFilterOp>& aFilters)
   : mBuilder(&aBuilder)
 {
-  WrRect scBounds = aParentSC.ToRelativeWrRect(aLayer->BoundsForStackingContext());
+  wr::LayoutRect scBounds = aParentSC.ToRelativeLayoutRect(aLayer->BoundsForStackingContext());
   if (aTransformPtr) {
     mTransform = *aTransformPtr;
   }
 
   mBuilder->PushStackingContext(scBounds,
                                 aAnimationsId,
                                 aOpacityPtr,
                                 aTransformPtr,
-                                WrTransformStyle::Flat,
-                                wr::ToWrMixBlendMode(aLayer->GetLayer()->GetMixBlendMode()),
+                                wr::TransformStyle::Flat,
+                                wr::ToMixBlendMode(aLayer->GetLayer()->GetMixBlendMode()),
                                 aFilters);
   mOrigin = aLayer->Bounds().TopLeft();
 }
 
 StackingContextHelper::~StackingContextHelper()
 {
   if (mBuilder) {
     mBuilder->PopStackingContext();
   }
 }
 
-WrRect
-StackingContextHelper::ToRelativeWrRect(const LayerRect& aRect) const
+wr::LayoutRect
+StackingContextHelper::ToRelativeLayoutRect(const LayerRect& aRect) const
 {
-  return wr::ToWrRect(aRect - mOrigin);
+  return wr::ToLayoutRect(aRect - mOrigin);
 }
 
-WrRect
-StackingContextHelper::ToRelativeWrRect(const LayoutDeviceRect& aRect) const
+wr::LayoutRect
+StackingContextHelper::ToRelativeLayoutRect(const LayoutDeviceRect& aRect) const
 {
-  return wr::ToWrRect(ViewAs<LayerPixel>(aRect, PixelCastJustification::WebRenderHasUnitResolution) - mOrigin);
+  return wr::ToLayoutRect(ViewAs<LayerPixel>(aRect, PixelCastJustification::WebRenderHasUnitResolution) - mOrigin);
 }
 
-WrPoint
-StackingContextHelper::ToRelativeWrPoint(const LayerPoint& aPoint) const
+wr::LayoutPoint
+StackingContextHelper::ToRelativeLayoutPoint(const LayerPoint& aPoint) const
 {
-  return wr::ToWrPoint(aPoint - mOrigin);
+  return wr::ToLayoutPoint(aPoint - mOrigin);
 }
 
-WrRect
-StackingContextHelper::ToRelativeWrRectRounded(const LayoutDeviceRect& aRect) const
+wr::LayoutRect
+StackingContextHelper::ToRelativeLayoutRectRounded(const LayoutDeviceRect& aRect) const
 {
-  return wr::ToWrRect(RoundedToInt(ViewAs<LayerPixel>(aRect, PixelCastJustification::WebRenderHasUnitResolution) - mOrigin));
+  return wr::ToLayoutRect(RoundedToInt(ViewAs<LayerPixel>(aRect, PixelCastJustification::WebRenderHasUnitResolution) - mOrigin));
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/StackingContextHelper.h
+++ b/gfx/layers/wr/StackingContextHelper.h
@@ -27,58 +27,58 @@ public:
   // Pushes a stacking context onto the provided DisplayListBuilder. It uses
   // the transform if provided, otherwise takes the transform from the layer.
   // It also takes the mix-blend-mode and bounds from the layer, and uses 1.0
   // for the opacity.
   StackingContextHelper(const StackingContextHelper& aParentSC,
                         wr::DisplayListBuilder& aBuilder,
                         WebRenderLayer* aLayer,
                         const Maybe<gfx::Matrix4x4>& aTransform = Nothing(),
-                        const nsTArray<WrFilterOp>& aFilters = nsTArray<WrFilterOp>());
+                        const nsTArray<wr::WrFilterOp>& aFilters = nsTArray<wr::WrFilterOp>());
   // Alternate constructor which invokes the version of PushStackingContext
   // for animations.
   StackingContextHelper(const StackingContextHelper& aParentSC,
                         wr::DisplayListBuilder& aBuilder,
                         WebRenderLayer* aLayer,
                         uint64_t aAnimationsId,
                         float* aOpacityPtr,
                         gfx::Matrix4x4* aTransformPtr,
-                        const nsTArray<WrFilterOp>& aFilters = nsTArray<WrFilterOp>());
+                        const nsTArray<wr::WrFilterOp>& aFilters = nsTArray<wr::WrFilterOp>());
   // The constructor for layers-free mode.
   StackingContextHelper(const StackingContextHelper& aParentSC,
                         wr::DisplayListBuilder& aBuilder,
                         LayerRect aBoundForSC,
                         LayerPoint aOrigin,
                         uint64_t aAnimationsId,
                         float* aOpacityPtr,
                         gfx::Matrix4x4* aTransformPtr,
-                        const nsTArray<WrFilterOp>& aFilters = nsTArray<WrFilterOp>());
+                        const nsTArray<wr::WrFilterOp>& aFilters = nsTArray<wr::WrFilterOp>());
   // This version of the constructor should only be used at the root level
   // of the tree, so that we have a StackingContextHelper to pass down into
   // the RenderLayer traversal, but don't actually want it to push a stacking
   // context on the display list builder.
   StackingContextHelper();
 
   // Pops the stacking context, if one was pushed during the constructor.
   ~StackingContextHelper();
 
   // When this StackingContextHelper is in scope, this function can be used
-  // to convert a rect from the layer system's coordinate space to a WrRect
+  // to convert a rect from the layer system's coordinate space to a LayoutRect
   // that is relative to the stacking context. This is useful because most
   // things that are pushed inside the stacking context need to be relative
   // to the stacking context.
   // We allow passing in a LayoutDeviceRect for convenience because in a lot of
   // cases with WebRender display item generate the layout device space is the
   // same as the layer space. (TODO: try to make this more explicit somehow).
-  WrRect ToRelativeWrRect(const LayerRect& aRect) const;
-  WrRect ToRelativeWrRect(const LayoutDeviceRect& aRect) const;
+  wr::LayoutRect ToRelativeLayoutRect(const LayerRect& aRect) const;
+  wr::LayoutRect ToRelativeLayoutRect(const LayoutDeviceRect& aRect) const;
   // Same but for points
-  WrPoint ToRelativeWrPoint(const LayerPoint& aPoint) const;
+  wr::LayoutPoint ToRelativeLayoutPoint(const LayerPoint& aPoint) const;
   // Same but rounds the rectangle to ints after transforming.
-  WrRect ToRelativeWrRectRounded(const LayoutDeviceRect& aRect) const;
+  wr::LayoutRect ToRelativeLayoutRectRounded(const LayoutDeviceRect& aRect) const;
 
 private:
   wr::DisplayListBuilder* mBuilder;
   LayerPoint mOrigin;
   gfx::Matrix4x4 mTransform;
 };
 
 } // namespace layers
--- a/gfx/layers/wr/WebRenderBridgeChild.cpp
+++ b/gfx/layers/wr/WebRenderBridgeChild.cpp
@@ -103,17 +103,17 @@ WebRenderBridgeChild::DPEnd(wr::DisplayL
                             bool aIsSync,
                             uint64_t aTransactionId,
                             const WebRenderScrollData& aScrollData)
 {
   MOZ_ASSERT(!mDestroyed);
   MOZ_ASSERT(mIsInTransaction);
 
   wr::BuiltDisplayList dl;
-  WrSize contentSize;
+  wr::LayoutSize contentSize;
   aBuilder.Finalize(contentSize, dl);
   ByteBuffer dlData(Move(dl.dl));
 
   if (aIsSync) {
     this->SendDPSyncEnd(aSize, mParentCommands, mDestroyedActors, GetFwdTransactionId(), aTransactionId,
                         contentSize, dlData, dl.dl_desc, aScrollData, mIdNamespace);
   } else {
     this->SendDPEnd(aSize, mParentCommands, mDestroyedActors, GetFwdTransactionId(), aTransactionId,
@@ -201,37 +201,37 @@ WriteFontFileData(const uint8_t* aData, 
 void
 WebRenderBridgeChild::PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArray<GlyphArray>& aGlyphs,
                                  gfx::ScaledFont* aFont, const StackingContextHelper& aSc,
                                  const LayerRect& aBounds, const LayerRect& aClip)
 {
   MOZ_ASSERT(aFont);
   MOZ_ASSERT(!aGlyphs.IsEmpty());
 
-  WrFontKey key = GetFontKeyForScaledFont(aFont);
+  wr::WrFontKey key = GetFontKeyForScaledFont(aFont);
   MOZ_ASSERT(key.mNamespace && key.mHandle);
 
   for (size_t i = 0; i < aGlyphs.Length(); i++) {
     GlyphArray glyph_array = aGlyphs[i];
     nsTArray<gfx::Glyph>& glyphs = glyph_array.glyphs();
 
-    nsTArray<WrGlyphInstance> wr_glyph_instances;
+    nsTArray<wr::GlyphInstance> wr_glyph_instances;
     wr_glyph_instances.SetLength(glyphs.Length());
 
     for (size_t j = 0; j < glyphs.Length(); j++) {
       wr_glyph_instances[j].index = glyphs[j].mIndex;
-      wr_glyph_instances[j].point = aSc.ToRelativeWrPoint(
+      wr_glyph_instances[j].point = aSc.ToRelativeLayoutPoint(
               LayerPoint::FromUnknownPoint(glyphs[j].mPosition));
     }
 
-    aBuilder.PushText(aSc.ToRelativeWrRect(aBounds),
-                      aSc.ToRelativeWrRect(aClip),
+    aBuilder.PushText(aSc.ToRelativeLayoutRect(aBounds),
+                      aSc.ToRelativeLayoutRect(aClip),
                       glyph_array.color().value(),
                       key,
-                      Range<const WrGlyphInstance>(wr_glyph_instances.Elements(), wr_glyph_instances.Length()),
+                      Range<const wr::GlyphInstance>(wr_glyph_instances.Elements(), wr_glyph_instances.Length()),
                       aFont->GetSize());
 
   }
 }
 
 wr::FontKey
 WebRenderBridgeChild::GetFontKeyForScaledFont(gfx::ScaledFont* aScaledFont)
 {
--- a/gfx/layers/wr/WebRenderBridgeChild.h
+++ b/gfx/layers/wr/WebRenderBridgeChild.h
@@ -91,19 +91,19 @@ public:
 
   uint32_t GetNextResourceId() { return ++mResourceId; }
   uint32_t GetNamespace() { return mIdNamespace; }
   void SetNamespace(uint32_t aIdNamespace)
   {
     mIdNamespace = aIdNamespace;
   }
 
-  WrImageKey GetNextImageKey()
+  wr::WrImageKey GetNextImageKey()
   {
-    return WrImageKey{ GetNamespace(), GetNextResourceId() };
+    return wr::WrImageKey{ GetNamespace(), GetNextResourceId() };
   }
 
   void PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArray<GlyphArray>& aGlyphs,
                   gfx::ScaledFont* aFont, const StackingContextHelper& aSc,
                   const LayerRect& aBounds, const LayerRect& aClip);
 
   wr::FontKey GetFontKeyForScaledFont(gfx::ScaledFont* aScaledFont);
 
--- a/gfx/layers/wr/WebRenderBridgeParent.cpp
+++ b/gfx/layers/wr/WebRenderBridgeParent.cpp
@@ -395,19 +395,19 @@ WebRenderBridgeParent::RecvDPBegin(const
 }
 
 void
 WebRenderBridgeParent::HandleDPEnd(const gfx::IntSize& aSize,
                                  InfallibleTArray<WebRenderParentCommand>&& aCommands,
                                  InfallibleTArray<OpDestroy>&& aToDestroy,
                                  const uint64_t& aFwdTransactionId,
                                  const uint64_t& aTransactionId,
-                                 const WrSize& aContentSize,
-                                 const ByteBuffer& dl,
-                                 const WrBuiltDisplayListDescriptor& dlDesc,
+                                 const wr::LayoutSize& aContentSize,
+                                 const wr::ByteBuffer& dl,
+                                 const wr::BuiltDisplayListDescriptor& dlDesc,
                                  const WebRenderScrollData& aScrollData,
                                  const uint32_t& aIdNameSpace)
 {
   AutoProfilerTracing tracing("Paint", "DPTransaction");
   UpdateFwdTransactionId(aFwdTransactionId);
   AutoClearReadLocks clearLocks(mReadLocks);
 
   if (mDestroyed) {
@@ -475,17 +475,17 @@ WebRenderBridgeParent::UpdateAPZ()
                            mScrollData.GetFocusTarget());
     apzc->UpdateHitTestingTree(rootLayersId, rootWrbp->GetScrollData(),
         mScrollData.IsFirstPaint(), GetLayersId(),
         mScrollData.GetPaintSequenceNumber());
   }
 }
 
 bool
-WebRenderBridgeParent::PushAPZStateToWR(nsTArray<WrTransformProperty>& aTransformArray)
+WebRenderBridgeParent::PushAPZStateToWR(nsTArray<wr::WrTransformProperty>& aTransformArray)
 {
   CompositorBridgeParent* cbp = GetRootCompositorBridgeParent();
   if (!cbp) {
     return false;
   }
   if (RefPtr<APZCTreeManager> apzc = cbp->GetAPZCTreeManager()) {
     TimeStamp animationTime = cbp->GetTestingTimeStamp().valueOr(
         mCompositorScheduler->GetLastComposeTime());
@@ -508,19 +508,19 @@ WebRenderBridgeParent::GetScrollData() c
 }
 
 mozilla::ipc::IPCResult
 WebRenderBridgeParent::RecvDPEnd(const gfx::IntSize& aSize,
                                  InfallibleTArray<WebRenderParentCommand>&& aCommands,
                                  InfallibleTArray<OpDestroy>&& aToDestroy,
                                  const uint64_t& aFwdTransactionId,
                                  const uint64_t& aTransactionId,
-                                 const WrSize& aContentSize,
-                                 const ByteBuffer& dl,
-                                 const WrBuiltDisplayListDescriptor& dlDesc,
+                                 const wr::LayoutSize& aContentSize,
+                                 const wr::ByteBuffer& dl,
+                                 const wr::BuiltDisplayListDescriptor& dlDesc,
                                  const WebRenderScrollData& aScrollData,
                                  const uint32_t& aIdNameSpace)
 {
   if (mDestroyed) {
     return IPC_OK();
   }
   HandleDPEnd(aSize, Move(aCommands), Move(aToDestroy), aFwdTransactionId, aTransactionId,
               aContentSize, dl, dlDesc, aScrollData, aIdNameSpace);
@@ -528,19 +528,19 @@ WebRenderBridgeParent::RecvDPEnd(const g
 }
 
 mozilla::ipc::IPCResult
 WebRenderBridgeParent::RecvDPSyncEnd(const gfx::IntSize &aSize,
                                      InfallibleTArray<WebRenderParentCommand>&& aCommands,
                                      InfallibleTArray<OpDestroy>&& aToDestroy,
                                      const uint64_t& aFwdTransactionId,
                                      const uint64_t& aTransactionId,
-                                     const WrSize& aContentSize,
-                                     const ByteBuffer& dl,
-                                     const WrBuiltDisplayListDescriptor& dlDesc,
+                                     const wr::LayoutSize& aContentSize,
+                                     const wr::ByteBuffer& dl,
+                                     const wr::BuiltDisplayListDescriptor& dlDesc,
                                      const WebRenderScrollData& aScrollData,
                                      const uint32_t& aIdNameSpace)
 {
   if (mDestroyed) {
     return IPC_OK();
   }
   HandleDPEnd(aSize, Move(aCommands), Move(aToDestroy), aFwdTransactionId, aTransactionId,
               aContentSize, dl, dlDesc, aScrollData, aIdNameSpace);
@@ -651,18 +651,18 @@ WebRenderBridgeParent::ProcessWebRenderP
       }
     }
   }
 }
 
 void
 WebRenderBridgeParent::ProcessWebRenderCommands(const gfx::IntSize &aSize,
                                                 InfallibleTArray<WebRenderParentCommand>& aCommands, const wr::Epoch& aEpoch,
-                                                const WrSize& aContentSize, const ByteBuffer& dl,
-                                                const WrBuiltDisplayListDescriptor& dlDesc,
+                                                const wr::LayoutSize& aContentSize, const wr::ByteBuffer& dl,
+                                                const wr::BuiltDisplayListDescriptor& dlDesc,
                                                 const uint32_t& aIdNameSpace)
 {
   mCompositableHolder->SetCompositionTime(TimeStamp::Now());
   ProcessWebRenderParentCommands(aCommands);
 
   // The command is obsoleted.
   // Do not set the command to webrender since it causes crash in webrender.
   if (mIdNameSpace != aIdNameSpace) {
@@ -1052,18 +1052,18 @@ WebRenderBridgeParent::AdvanceAnimations
   TimeStamp animTime = mCompositorScheduler->GetLastComposeTime();
   if (CompositorBridgeParent* cbp = GetRootCompositorBridgeParent()) {
     animTime = cbp->GetTestingTimeStamp().valueOr(animTime);
   }
   AnimationHelper::SampleAnimations(mAnimStorage, animTime);
 }
 
 void
-WebRenderBridgeParent::SampleAnimations(nsTArray<WrOpacityProperty>& aOpacityArray,
-                                        nsTArray<WrTransformProperty>& aTransformArray)
+WebRenderBridgeParent::SampleAnimations(nsTArray<wr::WrOpacityProperty>& aOpacityArray,
+                                        nsTArray<wr::WrTransformProperty>& aTransformArray)
 {
   AdvanceAnimations();
 
   // return the animated data if has
   if (mAnimStorage->AnimatedValueCount()) {
     for(auto iter = mAnimStorage->ConstAnimatedValueTableIter();
         !iter.Done(); iter.Next()) {
       AnimatedValue * value = iter.UserData();
@@ -1091,18 +1091,18 @@ WebRenderBridgeParent::CompositeToTarget
   if (!mForceRendering &&
       wr::RenderThread::Get()->GetPendingFrameCount(mApi->GetId()) > maxPendingFrameCount) {
     // Render thread is busy, try next time.
     ScheduleComposition();
     return;
   }
 
   bool scheduleComposite = false;
-  nsTArray<WrOpacityProperty> opacityArray;
-  nsTArray<WrTransformProperty> transformArray;
+  nsTArray<wr::WrOpacityProperty> opacityArray;
+  nsTArray<wr::WrTransformProperty> transformArray;
 
   mCompositableHolder->SetCompositionTime(TimeStamp::Now());
   mCompositableHolder->ApplyAsyncImages(mApi);
 
   if (gfxPrefs::WebRenderOMTAEnabled()) {
     SampleAnimations(opacityArray, transformArray);
 
     if (!transformArray.IsEmpty() || !opacityArray.IsEmpty()) {
--- a/gfx/layers/wr/WebRenderBridgeParent.h
+++ b/gfx/layers/wr/WebRenderBridgeParent.h
@@ -93,29 +93,29 @@ public:
                                          const uint32_t& aFontIndex) override;
   mozilla::ipc::IPCResult RecvDeleteFont(const wr::FontKey& aFontKey) override;
   mozilla::ipc::IPCResult RecvDPBegin(const gfx::IntSize& aSize) override;
   mozilla::ipc::IPCResult RecvDPEnd(const gfx::IntSize& aSize,
                                     InfallibleTArray<WebRenderParentCommand>&& aCommands,
                                     InfallibleTArray<OpDestroy>&& aToDestroy,
                                     const uint64_t& aFwdTransactionId,
                                     const uint64_t& aTransactionId,
-                                    const WrSize& aContentSize,
-                                    const ByteBuffer& dl,
-                                    const WrBuiltDisplayListDescriptor& dlDesc,
+                                    const wr::LayoutSize& aContentSize,
+                                    const wr::ByteBuffer& dl,
+                                    const wr::BuiltDisplayListDescriptor& dlDesc,
                                     const WebRenderScrollData& aScrollData,
                                     const uint32_t& aIdNameSpace) override;
   mozilla::ipc::IPCResult RecvDPSyncEnd(const gfx::IntSize& aSize,
                                         InfallibleTArray<WebRenderParentCommand>&& aCommands,
                                         InfallibleTArray<OpDestroy>&& aToDestroy,
                                         const uint64_t& aFwdTransactionId,
                                         const uint64_t& aTransactionId,
-                                        const WrSize& aContentSize,
-                                        const ByteBuffer& dl,
-                                        const WrBuiltDisplayListDescriptor& dlDesc,
+                                        const wr::LayoutSize& aContentSize,
+                                        const wr::ByteBuffer& dl,
+                                        const wr::BuiltDisplayListDescriptor& dlDesc,
                                         const WebRenderScrollData& aScrollData,
                                         const uint32_t& aIdNameSpace) override;
   mozilla::ipc::IPCResult RecvParentCommands(nsTArray<WebRenderParentCommand>&& commands) override;
   mozilla::ipc::IPCResult RecvDPGetSnapshot(PTextureParent* aTexture) override;
 
   mozilla::ipc::IPCResult RecvAddPipelineIdForAsyncCompositable(const wr::PipelineId& aPipelineIds,
                                                                 const CompositableHandle& aHandle) override;
   mozilla::ipc::IPCResult RecvRemovePipelineIdForAsyncCompositable(const wr::PipelineId& aPipelineId) override;
@@ -212,46 +212,46 @@ private:
   virtual ~WebRenderBridgeParent();
 
   uint64_t GetLayersId() const;
   void DeleteOldImages();
   void ProcessWebRenderParentCommands(InfallibleTArray<WebRenderParentCommand>& aCommands);
   void ProcessWebRenderCommands(const gfx::IntSize &aSize,
                                 InfallibleTArray<WebRenderParentCommand>& commands,
                                 const wr::Epoch& aEpoch,
-                                const WrSize& aContentSize,
-                                const ByteBuffer& dl,
-                                const WrBuiltDisplayListDescriptor& dlDesc,
+                                const wr::LayoutSize& aContentSize,
+                                const wr::ByteBuffer& dl,
+                                const wr::BuiltDisplayListDescriptor& dlDesc,
                                 const uint32_t& aIdNameSpace);
   void ClearResources();
   uint64_t GetChildLayerObserverEpoch() const { return mChildLayerObserverEpoch; }
   bool ShouldParentObserveEpoch();
   void HandleDPEnd(const gfx::IntSize& aSize,
                    InfallibleTArray<WebRenderParentCommand>&& aCommands,
                    InfallibleTArray<OpDestroy>&& aToDestroy,
                    const uint64_t& aFwdTransactionId,
                    const uint64_t& aTransactionId,
-                   const WrSize& aContentSize,
-                   const ByteBuffer& dl,
-                   const WrBuiltDisplayListDescriptor& dlDesc,
+                   const wr::LayoutSize& aContentSize,
+                   const wr::ByteBuffer& dl,
+                   const wr::BuiltDisplayListDescriptor& dlDesc,
                    const WebRenderScrollData& aScrollData,
                    const uint32_t& aIdNameSpace);
   mozilla::ipc::IPCResult HandleShutdown();
 
   void AdvanceAnimations();
-  void SampleAnimations(nsTArray<WrOpacityProperty>& aOpacityArray,
-                        nsTArray<WrTransformProperty>& aTransformArray);
+  void SampleAnimations(nsTArray<wr::WrOpacityProperty>& aOpacityArray,
+                        nsTArray<wr::WrTransformProperty>& aTransformArray);
 
   CompositorBridgeParent* GetRootCompositorBridgeParent() const;
 
   // Have APZ push the async scroll state to WR. Returns true if an APZ
   // animation is in effect and we need to schedule another composition.
   // If scrollbars need their transforms updated, the provided aTransformArray
   // is populated with the property update details.
-  bool PushAPZStateToWR(nsTArray<WrTransformProperty>& aTransformArray);
+  bool PushAPZStateToWR(nsTArray<wr::WrTransformProperty>& aTransformArray);
 
   // Helper method to get an APZC reference from a scroll id. Uses the layers
   // id of this bridge, and may return null if the APZC wasn't found.
   already_AddRefed<AsyncPanZoomController> GetTargetAPZC(const FrameMetrics::ViewID& aId);
 
 private:
   struct PendingTransactionId {
     PendingTransactionId(wr::Epoch aEpoch, uint64_t aId)
--- a/gfx/layers/wr/WebRenderCanvasLayer.cpp
+++ b/gfx/layers/wr/WebRenderCanvasLayer.cpp
@@ -78,21 +78,21 @@ WebRenderCanvasLayer::RenderLayer(wr::Di
   wr::ImageRendering filter = wr::ToImageRendering(mSamplingFilter);
 
   if (gfxPrefs::LayersDump()) {
     printf_stderr("CanvasLayer %p texture-filter=%s\n",
                   this->GetLayer(),
                   Stringify(filter).c_str());
   }
 
-  WrImageKey key = GetImageKey();
+  wr::WrImageKey key = GetImageKey();
   WrBridge()->AddWebRenderParentCommand(OpAddExternalImage(mExternalImageId.value(), key));
   WrManager()->AddImageKeyForDiscard(key);
 
-  WrRect r = sc.ToRelativeWrRect(rect);
+  wr::LayoutRect r = sc.ToRelativeLayoutRect(rect);
   aBuilder.PushImage(r, r, filter, key);
 }
 
 void
 WebRenderCanvasLayer::AttachCompositable()
 {
   mCanvasClient->Connect();
 }
--- a/gfx/layers/wr/WebRenderColorLayer.cpp
+++ b/gfx/layers/wr/WebRenderColorLayer.cpp
@@ -23,14 +23,14 @@ WebRenderColorLayer::RenderLayer(wr::Dis
                                  const StackingContextHelper& aSc)
 {
   ScrollingLayersHelper scroller(this, aBuilder, aSc);
   StackingContextHelper sc(aSc, aBuilder, this);
 
   LayerRect rect = Bounds();
   DumpLayerInfo("ColorLayer", rect);
 
-  WrRect r = sc.ToRelativeWrRect(rect);
-  aBuilder.PushRect(r, r, wr::ToWrColor(mColor));
+  wr::LayoutRect r = sc.ToRelativeLayoutRect(rect);
+  aBuilder.PushRect(r, r, wr::ToColorF(mColor));
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/WebRenderCompositableHolder.cpp
+++ b/gfx/layers/wr/WebRenderCompositableHolder.cpp
@@ -14,18 +14,18 @@
 
 namespace mozilla {
 namespace layers {
 
 WebRenderCompositableHolder::AsyncImagePipelineHolder::AsyncImagePipelineHolder()
  : mInitialised(false)
  , mIsChanged(false)
  , mUseExternalImage(false)
- , mFilter(WrImageRendering::Auto)
- , mMixBlendMode(WrMixBlendMode::Normal)
+ , mFilter(wr::ImageRendering::Auto)
+ , mMixBlendMode(wr::MixBlendMode::Normal)
 {}
 
 WebRenderCompositableHolder::WebRenderCompositableHolder(uint32_t aIdNamespace)
  : mIdNamespace(aIdNamespace)
  , mResourceId(0)
  , mAsyncImageEpoch(0)
  , mDestroyed(false)
 {
@@ -130,18 +130,18 @@ WebRenderCompositableHolder::RemoveAsync
   }
 }
 
 void
 WebRenderCompositableHolder::UpdateAsyncImagePipeline(const wr::PipelineId& aPipelineId,
                                                       const LayerRect& aScBounds,
                                                       const gfx::Matrix4x4& aScTransform,
                                                       const gfx::MaybeIntSize& aScaleToSize,
-                                                      const WrImageRendering& aFilter,
-                                                      const WrMixBlendMode& aMixBlendMode)
+                                                      const wr::ImageRendering& aFilter,
+                                                      const wr::MixBlendMode& aMixBlendMode)
 {
   if (mDestroyed) {
     return;
   }
   AsyncImagePipelineHolder* holder = mAsyncImagePipelineHolders.Get(wr::AsUint64(aPipelineId));
   if (!holder) {
     return;
   }
@@ -259,57 +259,57 @@ WebRenderCompositableHolder::ApplyAsyncI
                                              useExternalImage,
                                              holder,
                                              keys,
                                              keysToDelete);
     if (!updateDisplayList) {
       continue;
     }
 
-    WrSize contentSize { holder->mScBounds.width, holder->mScBounds.height };
+    wr::LayoutSize contentSize { holder->mScBounds.width, holder->mScBounds.height };
     wr::DisplayListBuilder builder(pipelineId, contentSize);
 
     if (!keys.IsEmpty()) {
       MOZ_ASSERT(holder->mCurrentTexture.get());
 
       float opacity = 1.0f;
-      builder.PushStackingContext(wr::ToWrRect(holder->mScBounds),
+      builder.PushStackingContext(wr::ToLayoutRect(holder->mScBounds),
                                   0,
                                   &opacity,
                                   holder->mScTransform.IsIdentity() ? nullptr : &holder->mScTransform,
-                                  WrTransformStyle::Flat,
+                                  wr::TransformStyle::Flat,
                                   holder->mMixBlendMode,
-                                  nsTArray<WrFilterOp>());
+                                  nsTArray<wr::WrFilterOp>());
 
       LayerRect rect(0, 0, holder->mCurrentTexture->GetSize().width, holder->mCurrentTexture->GetSize().height);
       if (holder->mScaleToSize.isSome()) {
         rect = LayerRect(0, 0, holder->mScaleToSize.value().width, holder->mScaleToSize.value().height);
       }
 
       if (useExternalImage) {
         MOZ_ASSERT(holder->mCurrentTexture->AsWebRenderTextureHost());
         Range<const wr::ImageKey> range_keys(&keys[0], keys.Length());
         holder->mCurrentTexture->PushExternalImage(builder,
-                                                   wr::ToWrRect(rect),
-                                                   wr::ToWrRect(rect),
+                                                   wr::ToLayoutRect(rect),
+                                                   wr::ToLayoutRect(rect),
                                                    holder->mFilter,
                                                    range_keys);
         HoldExternalImage(pipelineId, epoch, holder->mCurrentTexture->AsWebRenderTextureHost());
       } else {
         MOZ_ASSERT(keys.Length() == 1);
-        builder.PushImage(wr::ToWrRect(rect),
-                          wr::ToWrRect(rect),
+        builder.PushImage(wr::ToLayoutRect(rect),
+                          wr::ToLayoutRect(rect),
                           holder->mFilter,
                           keys[0]);
       }
       builder.PopStackingContext();
     }
 
     wr::BuiltDisplayList dl;
-    WrSize builderContentSize;
+    wr::LayoutSize builderContentSize;
     builder.Finalize(builderContentSize, dl);
     aApi->SetRootDisplayList(gfx::Color(0.f, 0.f, 0.f, 0.f), epoch, LayerSize(holder->mScBounds.width, holder->mScBounds.height),
                              pipelineId, builderContentSize,
                              dl.dl_desc, dl.dl.inner.data, dl.dl.inner.length);
   }
   DeleteOldAsyncImages(aApi);
   mKeysToDelete.SwapElements(keysToDelete);
 }
--- a/gfx/layers/wr/WebRenderCompositableHolder.h
+++ b/gfx/layers/wr/WebRenderCompositableHolder.h
@@ -70,18 +70,18 @@ public:
 
   void AddAsyncImagePipeline(const wr::PipelineId& aPipelineId, WebRenderImageHost* aImageHost);
   void RemoveAsyncImagePipeline(wr::WebRenderAPI* aApi, const wr::PipelineId& aPipelineId);
 
   void UpdateAsyncImagePipeline(const wr::PipelineId& aPipelineId,
                                 const LayerRect& aScBounds,
                                 const gfx::Matrix4x4& aScTransform,
                                 const gfx::MaybeIntSize& aScaleToSize,
-                                const WrImageRendering& aFilter,
-                                const WrMixBlendMode& aMixBlendMode);
+                                const wr::ImageRendering& aFilter,
+                                const wr::MixBlendMode& aMixBlendMode);
   void ApplyAsyncImages(wr::WebRenderAPI* aApi);
 
 private:
   void DeleteOldAsyncImages(wr::WebRenderAPI* aApi);
 
   uint32_t GetNextResourceId() { return ++mResourceId; }
   uint32_t GetNamespace() { return mIdNamespace; }
   wr::ImageKey GetImageKey()
@@ -112,18 +112,18 @@ private:
     AsyncImagePipelineHolder();
 
     bool mInitialised;
     bool mIsChanged;
     bool mUseExternalImage;
     LayerRect mScBounds;
     gfx::Matrix4x4 mScTransform;
     gfx::MaybeIntSize mScaleToSize;
-    WrImageRendering mFilter;
-    WrMixBlendMode mMixBlendMode;
+    wr::ImageRendering mFilter;
+    wr::MixBlendMode mMixBlendMode;
     RefPtr<WebRenderImageHost> mImageHost;
     CompositableTextureHostRef mCurrentTexture;
     nsTArray<wr::ImageKey> mKeys;
   };
 
   bool UpdateImageKeys(wr::WebRenderAPI* aApi,
                        bool& aUseExternalImage,
                        AsyncImagePipelineHolder* aHolder,
--- a/gfx/layers/wr/WebRenderContainerLayer.cpp
+++ b/gfx/layers/wr/WebRenderContainerLayer.cpp
@@ -109,17 +109,17 @@ WebRenderContainerLayer::RenderLayer(wr:
 
   if (transformForSC && transform.IsIdentity()) {
     // If the transform is an identity transform, strip it out so that WR
     // doesn't turn this stacking context into a reference frame, as it
     // affects positioning. Bug 1345577 tracks a better fix.
     transformForSC = nullptr;
   }
 
-  nsTArray<WrFilterOp> filters;
+  nsTArray<wr::WrFilterOp> filters;
   for (const CSSFilter& filter : this->GetFilterChain()) {
     filters.AppendElement(wr::ToWrFilterOp(filter));
   }
 
   ScrollingLayersHelper scroller(this, aBuilder, aSc);
   StackingContextHelper sc(aSc, aBuilder, this, animationsId, opacityForSC, transformForSC, filters);
 
   LayerRect rect = Bounds();
@@ -145,14 +145,14 @@ WebRenderRefLayer::RenderLayer(wr::Displ
   // we need to apply that transform to the bounds before we pass it on to WR.
   // The conversion from ParentLayerPixel to LayerPixel below is a result of
   // changing the reference layer from "this layer" to the "the layer that
   // created aSc".
   LayerRect rect = ViewAs<LayerPixel>(bounds,
       PixelCastJustification::MovingDownToChildren);
   DumpLayerInfo("RefLayer", rect);
 
-  WrRect r = aSc.ToRelativeWrRect(rect);
+  wr::LayoutRect r = aSc.ToRelativeLayoutRect(rect);
   aBuilder.PushIFrame(r, wr::AsPipelineId(mId));
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/WebRenderDisplayItemLayer.cpp
+++ b/gfx/layers/wr/WebRenderDisplayItemLayer.cpp
@@ -29,17 +29,17 @@ WebRenderDisplayItemLayer::RenderLayer(w
 {
   if (mVisibleRegion.IsEmpty()) {
     return;
   }
 
   ScrollingLayersHelper scroller(this, aBuilder, aSc);
 
   if (mItem) {
-    WrSize contentSize; // this won't actually be used by anything
+    wr::LayoutSize contentSize; // this won't actually be used by anything
     wr::DisplayListBuilder builder(WrBridge()->GetPipeline(), contentSize);
     // We might have recycled this layer. Throw away the old commands.
     mParentCommands.Clear();
 
     mItem->CreateWebRenderCommands(builder, aSc, mParentCommands, WrManager(),
                                    GetDisplayListBuilder());
     builder.Finalize(contentSize, mBuiltDisplayList);
   } else {
--- a/gfx/layers/wr/WebRenderImageLayer.cpp
+++ b/gfx/layers/wr/WebRenderImageLayer.cpp
@@ -162,17 +162,17 @@ WebRenderImageLayer::RenderLayer(wr::Dis
     // context need to be done manually and pushed over to the parent side,
     // where it will be done when we build the display list for the iframe.
     // That happens in WebRenderCompositableHolder.
 
     LayerRect rect = ViewAs<LayerPixel>(bounds,
         PixelCastJustification::MovingDownToChildren);
     DumpLayerInfo("Image Layer async", rect);
 
-    WrRect r = aSc.ToRelativeWrRect(rect);
+    wr::LayoutRect r = aSc.ToRelativeLayoutRect(rect);
     aBuilder.PushIFrame(r, mPipelineId.ref());
 
     gfx::Matrix4x4 scTransform = GetTransform();
     // Translate is applied as part of PushIFrame()
     scTransform.PostTranslate(-rect.x, -rect.y, 0);
     // Adjust transform as to apply origin
     LayerPoint scOrigin = Bounds().TopLeft();
     scTransform.PreTranslate(-scOrigin.x, -scOrigin.y, 0);
@@ -180,17 +180,17 @@ WebRenderImageLayer::RenderLayer(wr::Dis
     MaybeIntSize scaleToSize;
     if (mScaleMode != ScaleMode::SCALE_NONE) {
       NS_ASSERTION(mScaleMode == ScaleMode::STRETCH,
                    "No other scalemodes than stretch and none supported yet.");
       scaleToSize = Some(mScaleToSize);
     }
     LayerRect scBounds = BoundsForStackingContext();
     wr::ImageRendering filter = wr::ToImageRendering(mSamplingFilter);
-    wr::MixBlendMode mixBlendMode = wr::ToWrMixBlendMode(GetMixBlendMode());
+    wr::MixBlendMode mixBlendMode = wr::ToMixBlendMode(GetMixBlendMode());
 
     WrBridge()->AddWebRenderParentCommand(OpUpdateAsyncImagePipeline(mPipelineId.value(),
                                                                      scBounds,
                                                                      scTransform,
                                                                      scaleToSize,
                                                                      filter,
                                                                      mixBlendMode));
     return;
@@ -226,21 +226,21 @@ WebRenderImageLayer::RenderLayer(wr::Dis
   wr::ImageRendering filter = wr::ToImageRendering(mSamplingFilter);
 
   DumpLayerInfo("Image Layer", rect);
   if (gfxPrefs::LayersDump()) {
     printf_stderr("ImageLayer %p texture-filter=%s \n",
                   GetLayer(),
                   Stringify(filter).c_str());
   }
-  WrRect r = sc.ToRelativeWrRect(rect);
+  wr::LayoutRect r = sc.ToRelativeLayoutRect(rect);
   aBuilder.PushImage(r, r, filter, mKey.value());
 }
 
-Maybe<WrImageMask>
+Maybe<wr::WrImageMask>
 WebRenderImageLayer::RenderMaskLayer(const StackingContextHelper& aSc,
                                      const gfx::Matrix4x4& aTransform)
 {
   if (!mContainer) {
      return Nothing();
   }
 
   CompositableType type = GetImageClientType();
@@ -278,18 +278,18 @@ WebRenderImageLayer::RenderMaskLayer(con
                         mContainer,
                         mKey,
                         mExternalImageId.ref());
   if (mKey.isNothing()) {
     return Nothing();
   }
 
   gfx::IntSize size = image->GetSize();
-  WrImageMask imageMask;
+  wr::WrImageMask imageMask;
   imageMask.image = mKey.value();
   Rect maskRect = aTransform.TransformBounds(Rect(0, 0, size.width, size.height));
-  imageMask.rect = aSc.ToRelativeWrRect(ViewAs<LayerPixel>(maskRect));
+  imageMask.rect = aSc.ToRelativeLayoutRect(ViewAs<LayerPixel>(maskRect));
   imageMask.repeat = false;
   return Some(imageMask);
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/WebRenderImageLayer.h
+++ b/gfx/layers/wr/WebRenderImageLayer.h
@@ -28,18 +28,18 @@ public:
 
 protected:
   virtual ~WebRenderImageLayer();
 
 public:
   Layer* GetLayer() override { return this; }
   void RenderLayer(wr::DisplayListBuilder& aBuilder,
                    const StackingContextHelper& aSc) override;
-  Maybe<WrImageMask> RenderMaskLayer(const StackingContextHelper& aSc,
-                                     const gfx::Matrix4x4& aTransform) override;
+  Maybe<wr::WrImageMask> RenderMaskLayer(const StackingContextHelper& aSc,
+                                         const gfx::Matrix4x4& aTransform) override;
 
 protected:
   CompositableType GetImageClientType();
   void ClearWrResources();
 
   void AddWRVideoImage(size_t aChannelNumber);
 
   wr::MaybeExternalImageId mExternalImageId;
--- a/gfx/layers/wr/WebRenderLayer.cpp
+++ b/gfx/layers/wr/WebRenderLayer.cpp
@@ -26,26 +26,26 @@ WebRenderLayer::WrManager()
 }
 
 WebRenderBridgeChild*
 WebRenderLayer::WrBridge()
 {
   return WrManager()->WrBridge();
 }
 
-WrImageKey
+wr::WrImageKey
 WebRenderLayer::GetImageKey()
 {
-  WrImageKey key;
+  wr::WrImageKey key;
   key.mNamespace = WrBridge()->GetNamespace();
   key.mHandle = WrBridge()->GetNextResourceId();
   return key;
 }
 
-Maybe<WrImageMask>
+Maybe<wr::WrImageMask>
 WebRenderLayer::BuildWrMaskLayer(const StackingContextHelper& aRelativeTo)
 {
   if (GetLayer()->GetMaskLayer()) {
     WebRenderLayer* maskLayer = ToWebRenderLayer(GetLayer()->GetMaskLayer());
     gfx::Matrix4x4 transform = maskLayer->GetLayer()->GetTransform();
     return maskLayer->RenderMaskLayer(aRelativeTo, transform);
   }
 
@@ -106,32 +106,32 @@ WebRenderLayer::UpdateImageKey(ImageClie
     return aOldKey;
   }
 
   // Delete old key, we are generating a new key.
   if (aOldKey.isSome()) {
     WrManager()->AddImageKeyForDiscard(aOldKey.value());
   }
 
-  WrImageKey key = GetImageKey();
+  wr::WrImageKey key = GetImageKey();
   WrBridge()->AddWebRenderParentCommand(OpAddExternalImage(aExternalImageId, key));
   return Some(key);
 }
 
 void
 WebRenderLayer::DumpLayerInfo(const char* aLayerType, const LayerRect& aRect)
 {
   if (!gfxPrefs::LayersDump()) {
     return;
   }
 
   Layer* layer = GetLayer();
   Matrix4x4 transform = layer->GetTransform();
   LayerRect bounds = Bounds();
-  WrMixBlendMode mixBlendMode = wr::ToWrMixBlendMode(GetLayer()->GetMixBlendMode());
+  wr::MixBlendMode mixBlendMode = wr::ToMixBlendMode(GetLayer()->GetMixBlendMode());
 
   printf_stderr("%s %p using bounds=%s, transform=%s, rect=%s, clip=%s, mix-blend-mode=%s\n",
                 aLayerType,
                 layer,
                 Stringify(bounds).c_str(),
                 Stringify(transform).c_str(),
                 Stringify(aRect).c_str(),
                 layer->GetClipRect() ? Stringify(layer->GetClipRect().value()).c_str() : "none",
--- a/gfx/layers/wr/WebRenderLayer.h
+++ b/gfx/layers/wr/WebRenderLayer.h
@@ -21,17 +21,17 @@ class WebRenderLayerManager;
 typedef gfx::Matrix4x4Typed<LayerPixel, LayerPixel> BoundsTransformMatrix;
 
 class WebRenderLayer
 {
 public:
   virtual Layer* GetLayer() = 0;
   virtual void RenderLayer(wr::DisplayListBuilder& aBuilder,
                            const StackingContextHelper& aSc) = 0;
-  virtual Maybe<WrImageMask> RenderMaskLayer(const StackingContextHelper& aSc,
+  virtual Maybe<wr::WrImageMask> RenderMaskLayer(const StackingContextHelper& aSc,
                                              const gfx::Matrix4x4& aTransform)
   {
     MOZ_ASSERT(false);
     return Nothing();
   }
 
   virtual already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() { return nullptr; }
   static inline WebRenderLayer*
@@ -42,27 +42,27 @@ public:
 
   Maybe<wr::ImageKey> UpdateImageKey(ImageClientSingle* aImageClient,
                                      ImageContainer* aContainer,
                                      Maybe<wr::ImageKey>& aOldKey,
                                      wr::ExternalImageId& aExternalImageId);
 
   WebRenderLayerManager* WrManager();
   WebRenderBridgeChild* WrBridge();
-  WrImageKey GetImageKey();
+  wr::WrImageKey GetImageKey();
 
   LayerRect Bounds();
   LayerRect BoundsForStackingContext();
 
   // Builds a WrImageMask from the mask layer on this layer, if there is one.
   // The |aRelativeTo| parameter should be a reference to the stacking context
   // that we want this mask to be relative to. This is usually the stacking
   // context of the *parent* layer of |this|, because that is what the mask
   // is relative to in the layer tree.
-  Maybe<WrImageMask> BuildWrMaskLayer(const StackingContextHelper& aRelativeTo);
+  Maybe<wr::WrImageMask> BuildWrMaskLayer(const StackingContextHelper& aRelativeTo);
 
 protected:
   BoundsTransformMatrix BoundsTransform();
 
   void DumpLayerInfo(const char* aLayerType, const LayerRect& aRect);
 };
 
 } // namespace layers
--- a/gfx/layers/wr/WebRenderLayerManager.cpp
+++ b/gfx/layers/wr/WebRenderLayerManager.cpp
@@ -306,17 +306,17 @@ WebRenderLayerManager::PushImage(nsDispl
 {
   gfx::IntSize size;
   Maybe<wr::ImageKey> key = CreateImageKey(aItem, aContainer, aBuilder, aSc, size);
   if (!key) {
     return false;
   }
 
   wr::ImageRendering filter = wr::ImageRendering::Auto;
-  auto r = aSc.ToRelativeWrRect(aRect);
+  auto r = aSc.ToRelativeLayoutRect(aRect);
   aBuilder.PushImage(r, r, filter, key.value());
 
   return true;
 }
 
 static void
 PaintItemByDrawTarget(nsDisplayItem* aItem,
                       DrawTarget* aDT,
@@ -433,17 +433,17 @@ WebRenderLayerManager::PushItemAsImage(n
   }
 
   // Update current bounds to fallback data
   fallbackData->SetGeometry(Move(geometry));
   fallbackData->SetBounds(clippedBounds);
 
   MOZ_ASSERT(fallbackData->GetKey());
 
-  WrRect dest = aSc.ToRelativeWrRect(imageRect + offset);
+  wr::LayoutRect dest = aSc.ToRelativeLayoutRect(imageRect + offset);
   aBuilder.PushImage(dest,
                      dest,
                      wr::ImageRendering::Auto,
                      fallbackData->GetKey().value());
   return true;
 }
 
 void
@@ -477,17 +477,17 @@ WebRenderLayerManager::EndTransactionInt
   mAnimationReadyTime = TimeStamp::Now();
 
   LayoutDeviceIntSize size = mWidget->GetClientSize();
   if (!WrBridge()->DPBegin(size.ToUnknownSize())) {
     return false;
   }
   DiscardCompositorAnimations();
 
-  WrSize contentSize { (float)size.width, (float)size.height };
+  wr::LayoutSize contentSize { (float)size.width, (float)size.height };
   wr::DisplayListBuilder builder(WrBridge()->GetPipeline(), contentSize);
 
   if (mEndTransactionWithoutLayers) {
     // aDisplayList being null here means this is an empty transaction following a layers-free
     // transaction, so we reuse the previously built displaylist.
     if (aDisplayList && aDisplayListBuilder) {
       StackingContextHelper sc;
       mParentCommands.Clear();
--- a/gfx/layers/wr/WebRenderMessageUtils.h
+++ b/gfx/layers/wr/WebRenderMessageUtils.h
@@ -101,132 +101,132 @@ struct ParamTraits<mozilla::wr::Pipeline
   Read(const Message* aMsg, PickleIterator* aIter, mozilla::wr::PipelineId* aResult)
   {
     return ReadParam(aMsg, aIter, &aResult->mNamespace)
         && ReadParam(aMsg, aIter, &aResult->mHandle);
   }
 };
 
 template<>
-struct ParamTraits<WrImageFormat>
+struct ParamTraits<mozilla::wr::ImageFormat>
   : public ContiguousEnumSerializer<
-        WrImageFormat,
-        WrImageFormat::Invalid,
-        WrImageFormat::Sentinel>
+        mozilla::wr::ImageFormat,
+        mozilla::wr::ImageFormat::Invalid,
+        mozilla::wr::ImageFormat::Sentinel>
 {
 };
 
 template<>
-struct ParamTraits<WrSize>
+struct ParamTraits<mozilla::wr::LayoutSize>
 {
   static void
-  Write(Message* aMsg, const WrSize& aParam)
+  Write(Message* aMsg, const mozilla::wr::LayoutSize& aParam)
   {
     WriteParam(aMsg, aParam.width);
     WriteParam(aMsg, aParam.height);
   }
 
   static bool
-  Read(const Message* aMsg, PickleIterator* aIter, WrSize* aResult)
+  Read(const Message* aMsg, PickleIterator* aIter, mozilla::wr::LayoutSize* aResult)
   {
     return ReadParam(aMsg, aIter, &aResult->width)
         && ReadParam(aMsg, aIter, &aResult->height);
   }
 };
 
 template<>
-struct ParamTraits<WrRect>
+struct ParamTraits<mozilla::wr::LayoutRect>
 {
   static void
-  Write(Message* aMsg, const WrRect& aParam)
+  Write(Message* aMsg, const mozilla::wr::LayoutRect& aParam)
   {
-    WriteParam(aMsg, aParam.x);
-    WriteParam(aMsg, aParam.y);
-    WriteParam(aMsg, aParam.width);
-    WriteParam(aMsg, aParam.height);
+    WriteParam(aMsg, aParam.origin.x);
+    WriteParam(aMsg, aParam.origin.y);
+    WriteParam(aMsg, aParam.size.width);
+    WriteParam(aMsg, aParam.size.height);
   }
 
   static bool
-  Read(const Message* aMsg, PickleIterator* aIter, WrRect* aResult)
+  Read(const Message* aMsg, PickleIterator* aIter, mozilla::wr::LayoutRect* aResult)
   {
-    return ReadParam(aMsg, aIter, &aResult->x)
-        && ReadParam(aMsg, aIter, &aResult->y)
-        && ReadParam(aMsg, aIter, &aResult->width)
-        && ReadParam(aMsg, aIter, &aResult->height);
+    return ReadParam(aMsg, aIter, &aResult->origin.x)
+        && ReadParam(aMsg, aIter, &aResult->origin.y)
+        && ReadParam(aMsg, aIter, &aResult->size.width)
+        && ReadParam(aMsg, aIter, &aResult->size.height);
   }
 };
 
 template<>
-struct ParamTraits<WrPoint>
+struct ParamTraits<mozilla::wr::LayoutPoint>
 {
   static void
-  Write(Message* aMsg, const WrPoint& aParam)
+  Write(Message* aMsg, const mozilla::wr::LayoutPoint& aParam)
   {
     WriteParam(aMsg, aParam.x);
     WriteParam(aMsg, aParam.y);
   }
 
   static bool
-  Read(const Message* aMsg, PickleIterator* aIter, WrPoint* aResult)
+  Read(const Message* aMsg, PickleIterator* aIter, mozilla::wr::LayoutPoint* aResult)
   {
     return ReadParam(aMsg, aIter, &aResult->x) &&
            ReadParam(aMsg, aIter, &aResult->y);
   }
 };
 
 template<>
-struct ParamTraits<WrImageMask>
+struct ParamTraits<mozilla::wr::WrImageMask>
 {
   static void
-  Write(Message* aMsg, const WrImageMask& aParam)
+  Write(Message* aMsg, const mozilla::wr::WrImageMask& aParam)
   {
     WriteParam(aMsg, aParam.image);
     WriteParam(aMsg, aParam.rect);
     WriteParam(aMsg, aParam.repeat);
   }
 
   static bool
-  Read(const Message* aMsg, PickleIterator* aIter, WrImageMask* aResult)
+  Read(const Message* aMsg, PickleIterator* aIter, mozilla::wr::WrImageMask* aResult)
   {
     return ReadParam(aMsg, aIter, &aResult->image)
         && ReadParam(aMsg, aIter, &aResult->rect)
         && ReadParam(aMsg, aIter, &aResult->repeat);
   }
 };
 
 template<>
-struct ParamTraits<WrImageRendering>
+struct ParamTraits<mozilla::wr::ImageRendering>
   : public ContiguousEnumSerializer<
-        WrImageRendering,
-        WrImageRendering::Auto,
-        WrImageRendering::Sentinel>
+        mozilla::wr::ImageRendering,
+        mozilla::wr::ImageRendering::Auto,
+        mozilla::wr::ImageRendering::Sentinel>
 {
 };
 
 template<>
-struct ParamTraits<WrMixBlendMode>
+struct ParamTraits<mozilla::wr::MixBlendMode>
   : public ContiguousEnumSerializer<
-        WrMixBlendMode,
-        WrMixBlendMode::Normal,
-        WrMixBlendMode::Sentinel>
+        mozilla::wr::MixBlendMode,
+        mozilla::wr::MixBlendMode::Normal,
+        mozilla::wr::MixBlendMode::Sentinel>
 {
 };
 
 template<>
-struct ParamTraits<WrBuiltDisplayListDescriptor>
+struct ParamTraits<mozilla::wr::BuiltDisplayListDescriptor>
 {
   static void
-  Write(Message* aMsg, const WrBuiltDisplayListDescriptor& aParam)
+  Write(Message* aMsg, const mozilla::wr::BuiltDisplayListDescriptor& aParam)
   {
     WriteParam(aMsg, aParam.builder_start_time);
     WriteParam(aMsg, aParam.builder_finish_time);
   }
 
   static bool
-  Read(const Message* aMsg, PickleIterator* aIter, WrBuiltDisplayListDescriptor* aResult)
+  Read(const Message* aMsg, PickleIterator* aIter, mozilla::wr::BuiltDisplayListDescriptor* aResult)
   {
     return ReadParam(aMsg, aIter, &aResult->builder_start_time)
         && ReadParam(aMsg, aIter, &aResult->builder_finish_time);
   }
 };
 
 } // namespace IPC
 
--- a/gfx/layers/wr/WebRenderPaintedLayer.cpp
+++ b/gfx/layers/wr/WebRenderPaintedLayer.cpp
@@ -94,21 +94,21 @@ WebRenderPaintedLayer::CreateWebRenderDi
                                                   const StackingContextHelper& aSc)
 {
   ScrollingLayersHelper scroller(this, aBuilder, aSc);
   StackingContextHelper sc(aSc, aBuilder, this);
 
   LayerRect rect = Bounds();
   DumpLayerInfo("PaintedLayer", rect);
 
-  WrImageKey key = GetImageKey();
+  wr::WrImageKey key = GetImageKey();
   WrBridge()->AddWebRenderParentCommand(OpAddExternalImage(mExternalImageId.value(), key));
   WrManager()->AddImageKeyForDiscard(key);
 
-  WrRect r = sc.ToRelativeWrRect(rect);
+  wr::LayoutRect r = sc.ToRelativeLayoutRect(rect);
   aBuilder.PushImage(r, r, wr::ImageRendering::Auto, key);
 }
 
 void
 WebRenderPaintedLayer::RenderLayer(wr::DisplayListBuilder& aBuilder,
                                    const StackingContextHelper& aSc)
 {
   if (!SetupExternalImages()) {
--- a/gfx/layers/wr/WebRenderPaintedLayerBlob.cpp
+++ b/gfx/layers/wr/WebRenderPaintedLayerBlob.cpp
@@ -83,15 +83,15 @@ WebRenderPaintedLayerBlob::RenderLayer(w
     mImageBounds = visibleRegion.GetBounds();
   }
 
   ScrollingLayersHelper scroller(this, aBuilder, aSc);
   StackingContextHelper sc(aSc, aBuilder, this);
   LayerRect rect = Bounds();
   DumpLayerInfo("PaintedLayer", rect);
 
-  aBuilder.PushImage(sc.ToRelativeWrRect(LayerRect(mImageBounds)),
-                     sc.ToRelativeWrRect(rect),
+  aBuilder.PushImage(sc.ToRelativeLayoutRect(LayerRect(mImageBounds)),
+                     sc.ToRelativeLayoutRect(rect),
                      wr::ImageRendering::Auto, mImageKey.value());
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/WebRenderPaintedLayerBlob.h
+++ b/gfx/layers/wr/WebRenderPaintedLayerBlob.h
@@ -57,16 +57,16 @@ public:
   virtual void ClearCachedResources() override
   {
     ClearWrResources();
   }
   Layer* GetLayer() override { return this; }
   void RenderLayer(wr::DisplayListBuilder& aBuilder,
                    const StackingContextHelper& aSc) override;
 private:
-  Maybe<WrImageKey> mImageKey;
+  Maybe<wr::WrImageKey> mImageKey;
   LayerIntRect mImageBounds;
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif // GFX_WEBRENDERPAINTEDLAYERBLOB_H
--- a/gfx/layers/wr/WebRenderTextureHost.cpp
+++ b/gfx/layers/wr/WebRenderTextureHost.cpp
@@ -173,18 +173,18 @@ WebRenderTextureHost::AddWRImage(wr::Web
   MOZ_ASSERT(mWrappedTextureHost);
   MOZ_ASSERT(mExternalImageId == aExtID);
 
   mWrappedTextureHost->AddWRImage(aAPI, aImageKeys, aExtID);
 }
 
 void
 WebRenderTextureHost::PushExternalImage(wr::DisplayListBuilder& aBuilder,
-                                        const WrRect& aBounds,
-                                        const WrRect& aClip,
+                                        const wr::LayoutRect& aBounds,
+                                        const wr::LayoutRect& aClip,
                                         wr::ImageRendering aFilter,
                                         Range<const wr::ImageKey>& aImageKeys)
 {
   MOZ_ASSERT(mWrappedTextureHost);
   MOZ_ASSERT(aImageKeys.length() > 0);
 
   mWrappedTextureHost->PushExternalImage(aBuilder,
                                          aBounds,
--- a/gfx/layers/wr/WebRenderTextureHost.h
+++ b/gfx/layers/wr/WebRenderTextureHost.h
@@ -68,18 +68,18 @@ public:
   virtual void GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
                               const std::function<wr::ImageKey()>& aImageKeyAllocator) override;
 
   virtual void AddWRImage(wr::WebRenderAPI* aAPI,
                           Range<const wr::ImageKey>& aImageKeys,
                           const wr::ExternalImageId& aExtID) override;
 
   virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder,
-                                 const WrRect& aBounds,
-                                 const WrRect& aClip,
+                                 const wr::LayoutRect& aBounds,
+                                 const wr::LayoutRect& aClip,
                                  wr::ImageRendering aFilter,
                                  Range<const wr::ImageKey>& aImageKeys) override;
 
 protected:
   void CreateRenderTextureHost(const SurfaceDescriptor& aDesc, TextureHost* aTexture);
 
   RefPtr<TextureHost> mWrappedTextureHost;
   wr::ExternalImageId mExternalImageId;
--- a/gfx/layers/wr/WebRenderUserData.cpp
+++ b/gfx/layers/wr/WebRenderUserData.cpp
@@ -66,17 +66,17 @@ WebRenderImageData::UpdateImageKey(Image
     return mKey;
   }
 
   // Delete old key, we are generating a new key.
   if (mKey) {
     mWRManager->AddImageKeyForDiscard(mKey.value());
   }
 
-  WrImageKey key = WrBridge()->GetNextImageKey();
+  wr::WrImageKey key = WrBridge()->GetNextImageKey();
   mWRManager->WrBridge()->AddWebRenderParentCommand(OpAddExternalImage(mExternalImageId.value(), key));
   mKey = Some(key);
 
   return mKey;
 }
 
 already_AddRefed<ImageClient>
 WebRenderImageData::GetImageClient()
@@ -88,18 +88,18 @@ WebRenderImageData::GetImageClient()
 void
 WebRenderImageData::CreateAsyncImageWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
                                                       ImageContainer* aContainer,
                                                       const StackingContextHelper& aSc,
                                                       const LayerRect& aBounds,
                                                       const LayerRect& aSCBounds,
                                                       const Matrix4x4& aSCTransform,
                                                       const MaybeIntSize& aScaleToSize,
-                                                      const WrImageRendering& aFilter,
-                                                      const WrMixBlendMode& aMixBlendMode)
+                                                      const wr::ImageRendering& aFilter,
+                                                      const wr::MixBlendMode& aMixBlendMode)
 {
   MOZ_ASSERT(aContainer->IsAsync());
   if (!mPipelineId) {
     // Alloc async image pipeline id.
     mPipelineId = Some(WrBridge()->GetCompositorBridgeChild()->GetNextPipelineId());
     WrBridge()->AddPipelineIdForAsyncCompositable(mPipelineId.ref(),
                                                   aContainer->GetAsyncContainerHandle());
   }
@@ -109,17 +109,17 @@ WebRenderImageData::CreateAsyncImageWebR
   // Push IFrame for async image pipeline.
   //
   // We don't push a stacking context for this async image pipeline here.
   // Instead, we do it inside the iframe that hosts the image. As a result,
   // a bunch of the calculations normally done as part of that stacking
   // context need to be done manually and pushed over to the parent side,
   // where it will be done when we build the display list for the iframe.
   // That happens in WebRenderCompositableHolder.
-  WrRect r = aSc.ToRelativeWrRect(aBounds);
+  wr::LayoutRect r = aSc.ToRelativeLayoutRect(aBounds);
   aBuilder.PushIFrame(r, mPipelineId.ref());
 
   WrBridge()->AddWebRenderParentCommand(OpUpdateAsyncImagePipeline(mPipelineId.value(),
                                                                    aSCBounds,
                                                                    aSCTransform,
                                                                    aScaleToSize,
                                                                    aFilter,
                                                                    aMixBlendMode));
--- a/gfx/layers/wr/WebRenderUserData.h
+++ b/gfx/layers/wr/WebRenderUserData.h
@@ -62,18 +62,18 @@ public:
 
   void CreateAsyncImageWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
                                          ImageContainer* aContainer,
                                          const StackingContextHelper& aSc,
                                          const LayerRect& aBounds,
                                          const LayerRect& aSCBounds,
                                          const gfx::Matrix4x4& aSCTransform,
                                          const gfx::MaybeIntSize& aScaleToSize,
-                                         const WrImageRendering& aFilter,
-                                         const WrMixBlendMode& aMixBlendMode);
+                                         const wr::ImageRendering& aFilter,
+                                         const wr::MixBlendMode& aMixBlendMode);
 
   void CreateImageClientIfNeeded();
 
 protected:
   void CreateExternalImageIfNeeded();
 
   wr::MaybeExternalImageId mExternalImageId;
   Maybe<wr::ImageKey> mKey;
--- a/gfx/thebes/DeviceManagerDx.cpp
+++ b/gfx/thebes/DeviceManagerDx.cpp
@@ -169,21 +169,16 @@ DeviceManagerDx::ImportDeviceInfo(const 
   MOZ_ASSERT(!ProcessOwnsCompositor());
 
   mDeviceStatus = Some(aDeviceStatus);
 }
 
 void
 DeviceManagerDx::ExportDeviceInfo(D3D11DeviceStatus* aOut)
 {
-  // Even though the parent process might not own the compositor, we still
-  // populate DeviceManagerDx with device statistics (for simplicity).
-  // That means it still gets queried for compositor information.
-  MOZ_ASSERT(XRE_IsParentProcess() || XRE_GetProcessType() == GeckoProcessType_GPU);
-
   if (mDeviceStatus) {
     *aOut = mDeviceStatus.value();
   }
 }
 
 void
 DeviceManagerDx::CreateContentDevices()
 {
@@ -317,16 +312,30 @@ DeviceManagerDx::CreateCompositorDeviceH
     }
     return false;
   }
 
   aOutDevice = device;
   return true;
 }
 
+// Note that it's enough for us to just use a counter for a unique ID,
+// even though the counter isn't synchronized between processes. If we
+// start in the GPU process and wind up in the parent process, the
+// whole graphics stack is blown away anyway. But just in case, we
+// make gpu process IDs negative and parent process IDs positive.
+static inline int32_t
+GetNextDeviceCounter()
+{
+  static int32_t sDeviceCounter = 0;
+  return XRE_IsGPUProcess()
+         ? --sDeviceCounter
+         : ++sDeviceCounter;
+}
+
 void
 DeviceManagerDx::CreateCompositorDevice(FeatureState& d3d11)
 {
   if (gfxPrefs::LayersD3D11ForceWARP()) {
     CreateWARPCompositorDevice();
     return;
   }
 
@@ -374,25 +383,28 @@ DeviceManagerDx::CreateCompositorDevice(
                          FeatureStatus::Broken,
                          "RenderTargetViews need recreating");
   }
   if (XRE_IsParentProcess()) {
     // It seems like this may only happen when we're using the NVIDIA gpu
     D3D11Checks::WarnOnAdapterMismatch(device);
   }
 
-  int featureLevel = device->GetFeatureLevel();
+  uint32_t featureLevel = device->GetFeatureLevel();
   {
     MutexAutoLock lock(mDeviceLock);
     mCompositorDevice = device;
+
+    int32_t sequenceNumber = GetNextDeviceCounter();
     mDeviceStatus = Some(D3D11DeviceStatus(
       false,
       textureSharingWorks,
       featureLevel,
-      DxgiAdapterDesc::From(desc)));
+      DxgiAdapterDesc::From(desc),
+      sequenceNumber));
   }
   mCompositorDevice->SetExceptionMode(0);
 }
 
 bool
 DeviceManagerDx::CreateDevice(IDXGIAdapter* aAdapter,
                                  D3D_DRIVER_TYPE aDriverType,
                                  UINT aFlags,
@@ -470,21 +482,24 @@ DeviceManagerDx::CreateWARPCompositorDev
 
   DxgiAdapterDesc nullAdapter;
   PodZero(&nullAdapter);
 
   int featureLevel = device->GetFeatureLevel();
   {
     MutexAutoLock lock(mDeviceLock);
     mCompositorDevice = device;
+
+    int32_t sequenceNumber = GetNextDeviceCounter();
     mDeviceStatus = Some(D3D11DeviceStatus(
       true,
       textureSharingWorks,
       featureLevel,
-      nullAdapter));
+      nullAdapter,
+      sequenceNumber));
   }
   mCompositorDevice->SetExceptionMode(0);
 
   reporterWARP.SetSuccessful();
 }
 
 FeatureStatus
 DeviceManagerDx::CreateContentDevice()
--- a/gfx/thebes/gfxPrefs.h
+++ b/gfx/thebes/gfxPrefs.h
@@ -496,16 +496,17 @@ private:
   DECL_GFX_PREF(Live, "gl.require-hardware",                   RequireHardwareGL, bool, false);
   DECL_GFX_PREF(Live, "gl.use-tls-is-current",                 UseTLSIsCurrent, int32_t, 0);
 
   DECL_GFX_PREF(Once, "image.cache.size",                      ImageCacheSize, int32_t, 5*1024*1024);
   DECL_GFX_PREF(Once, "image.cache.timeweight",                ImageCacheTimeWeight, int32_t, 500);
   DECL_GFX_PREF(Live, "image.decode-immediately.enabled",      ImageDecodeImmediatelyEnabled, bool, false);
   DECL_GFX_PREF(Live, "image.downscale-during-decode.enabled", ImageDownscaleDuringDecodeEnabled, bool, true);
   DECL_GFX_PREF(Live, "image.infer-src-animation.threshold-ms", ImageInferSrcAnimationThresholdMS, uint32_t, 2000);
+  DECL_GFX_PREF(Live, "image.layout_network_priority",         ImageLayoutNetworkPriority, bool, true);
   DECL_GFX_PREF(Once, "image.mem.decode_bytes_at_a_time",      ImageMemDecodeBytesAtATime, uint32_t, 200000);
   DECL_GFX_PREF(Live, "image.mem.discardable",                 ImageMemDiscardable, bool, false);
   DECL_GFX_PREF(Once, "image.mem.animated.discardable",        ImageMemAnimatedDiscardable, bool, false);
   DECL_GFX_PREF(Live, "image.mem.shared",                      ImageMemShared, bool, false);
   DECL_GFX_PREF(Once, "image.mem.surfacecache.discard_factor", ImageMemSurfaceCacheDiscardFactor, uint32_t, 1);
   DECL_GFX_PREF(Once, "image.mem.surfacecache.max_size_kb",    ImageMemSurfaceCacheMaxSizeKB, uint32_t, 100 * 1024);
   DECL_GFX_PREF(Once, "image.mem.surfacecache.min_expiration_ms", ImageMemSurfaceCacheMinExpirationMS, uint32_t, 60*1000);
   DECL_GFX_PREF(Once, "image.mem.surfacecache.size_factor",    ImageMemSurfaceCacheSizeFactor, uint32_t, 64);
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -3,28 +3,30 @@
 /* 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 "gfxWindowsPlatform.h"
 
 #include "cairo.h"
 #include "mozilla/ArrayUtils.h"
+#include "mozilla/layers/CompositorBridgeChild.h"
 
 #include "gfxImageSurface.h"
 #include "gfxWindowsSurface.h"
 
 #include "nsUnicharUtils.h"
 
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "mozilla/Sprintf.h"
 #include "mozilla/WindowsVersion.h"
 #include "nsServiceManagerUtils.h"
 #include "nsTArray.h"
+#include "nsThreadUtils.h"
 #include "mozilla/Telemetry.h"
 #include "GeckoProfiler.h"
 
 #include "nsIWindowsRegKey.h"
 #include "nsIFile.h"
 #include "plbase64.h"
 #include "nsIXULRuntime.h"
 #include "imgLoader.h"
@@ -65,17 +67,17 @@
 #include <winternl.h>
 #include "d3dkmtQueryStatistics.h"
 
 #include "base/thread.h"
 #include "gfxPrefs.h"
 #include "gfxConfig.h"
 #include "VsyncSource.h"
 #include "DriverCrashGuard.h"
-#include "mozilla/dom/ContentParent.h"
+#include "mozilla/dom/ContentChild.h"
 #include "mozilla/gfx/DeviceManagerDx.h"
 #include "mozilla/layers/DeviceAttachmentsD3D11.h"
 #include "D3D11Checks.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 using namespace mozilla::layers;
 using namespace mozilla::widget;
@@ -889,22 +891,54 @@ gfxWindowsPlatform::SchedulePaintIfDevic
 
   DeviceResetReason resetReason = DeviceResetReason::OK;
   if (!DidRenderingDeviceReset(&resetReason)) {
     return;
   }
 
   gfxCriticalNote << "(gfxWindowsPlatform) Detected device reset: " << (int)resetReason;
 
-  // Trigger an ::OnPaint for each window.
-  ::EnumThreadWindows(GetCurrentThreadId(),
-                      InvalidateWindowForDeviceReset,
-                      0);
+  if (XRE_IsParentProcess()) {
+    // Trigger an ::OnPaint for each window.
+    ::EnumThreadWindows(GetCurrentThreadId(),
+                        InvalidateWindowForDeviceReset,
+                        0);
+  } else {
+    NS_DispatchToMainThread(NS_NewRunnableFunction(
+      "gfx::gfxWindowsPlatform::SchedulePaintIfDeviceReset",
+      []() -> void {
+        gfxWindowsPlatform::GetPlatform()->CheckForContentOnlyDeviceReset();
+      }
+    ));
+  }
+
+  gfxCriticalNote << "(gfxWindowsPlatform) scheduled device update.";
+}
 
-  gfxCriticalNote << "(gfxWindowsPlatform) Finished device reset.";
+void
+gfxWindowsPlatform::CheckForContentOnlyDeviceReset()
+{
+  if (!DidRenderingDeviceReset()) {
+    return;
+  }
+
+  bool isContentOnlyTDR;
+  D3D11DeviceStatus status;
+
+  DeviceManagerDx::Get()->ExportDeviceInfo(&status);
+  CompositorBridgeChild::Get()->SendCheckContentOnlyTDR(
+    status.sequenceNumber(), &isContentOnlyTDR);
+
+  // The parent process doesn't know about the reset yet, or the reset is
+  // local to our device.
+  if (isContentOnlyTDR) {
+    gfxCriticalNote << "A content-only TDR is detected.";
+    dom::ContentChild* cc = dom::ContentChild::GetSingleton();
+    cc->RecvReinitRenderingForDeviceReset();
+  }
 }
 
 void
 gfxWindowsPlatform::GetPlatformCMSOutputProfile(void* &mem, size_t &mem_size)
 {
     WCHAR str[MAX_PATH];
     DWORD size = MAX_PATH;
     BOOL res;
--- a/gfx/thebes/gfxWindowsPlatform.h
+++ b/gfx/thebes/gfxWindowsPlatform.h
@@ -175,16 +175,17 @@ public:
      * Check whether format is supported on a platform or not (if unclear, returns true)
      */
     virtual bool IsFontFormatSupported(uint32_t aFormatFlags) override;
 
     virtual void CompositorUpdated() override;
 
     bool DidRenderingDeviceReset(DeviceResetReason* aResetReason = nullptr) override;
     void SchedulePaintIfDeviceReset() override;
+    void CheckForContentOnlyDeviceReset();
 
     mozilla::gfx::BackendType GetContentBackendFor(mozilla::layers::LayersBackend aLayers) override;
 
     static void GetDLLVersion(char16ptr_t aDLLPath, nsAString& aVersion);
 
     // returns ClearType tuning information for each display
     static void GetCleartypeParams(nsTArray<ClearTypeParameterInfo>& aParams);
 
--- a/gfx/webrender_bindings/Moz2DImageRenderer.cpp
+++ b/gfx/webrender_bindings/Moz2DImageRenderer.cpp
@@ -85,22 +85,22 @@ static bool Moz2DRenderCallback(const Ra
   return ret;
 }
 
 } // namespace
 } // namespace
 
 extern "C" {
 
-bool wr_moz2d_render_cb(const WrByteSlice blob,
+bool wr_moz2d_render_cb(const mozilla::wr::ByteSlice blob,
                         uint32_t width, uint32_t height,
                         mozilla::wr::ImageFormat aFormat,
-                        MutByteSlice output)
+                        mozilla::wr::MutByteSlice output)
 {
   return mozilla::wr::Moz2DRenderCallback(mozilla::wr::ByteSliceToRange(blob),
                                           mozilla::gfx::IntSize(width, height),
-                                          mozilla::wr::WrImageFormatToSurfaceFormat(aFormat),
+                                          mozilla::wr::ImageFormatToSurfaceFormat(aFormat),
                                           mozilla::wr::MutByteSliceToRange(output));
 }
 
 } // extern
 
 
--- a/gfx/webrender_bindings/RenderThread.cpp
+++ b/gfx/webrender_bindings/RenderThread.cpp
@@ -185,22 +185,22 @@ RenderThread::RunEvent(wr::WindowId aWin
   }
 
   aEvent->Run(*this, aWindowId);
   aEvent = nullptr;
 }
 
 static void
 NotifyDidRender(layers::CompositorBridgeParentBase* aBridge,
-                WrRenderedEpochs* aEpochs,
+                wr::WrRenderedEpochs* aEpochs,
                 TimeStamp aStart,
                 TimeStamp aEnd)
 {
-  WrPipelineId pipeline;
-  WrEpoch epoch;
+  wr::WrPipelineId pipeline;
+  wr::WrEpoch epoch;
   while (wr_rendered_epochs_next(aEpochs, &pipeline, &epoch)) {
     aBridge->NotifyDidCompositeToPipeline(pipeline, epoch, aStart, aEnd);
   }
   wr_rendered_epochs_delete(aEpochs);
 }
 
 void
 RenderThread::UpdateAndRender(wr::WindowId aWindowId)
@@ -347,17 +347,17 @@ RenderThread::UnregisterExternalImage(ui
 
 void
 RenderThread::DeferredRenderTextureHostDestroy(RefPtr<RenderTextureHost>)
 {
   // Do nothing. Just decrease the ref-count of RenderTextureHost.
 }
 
 RenderTextureHost*
-RenderThread::GetRenderTexture(WrExternalImageId aExternalImageId)
+RenderThread::GetRenderTexture(wr::WrExternalImageId aExternalImageId)
 {
   MOZ_ASSERT(IsInRenderThread());
 
   MutexAutoLock lock(mRenderTextureMapLock);
   MOZ_ASSERT(mRenderTextures.GetWeak(aExternalImageId.mHandle));
   return mRenderTextures.GetWeak(aExternalImageId.mHandle);
 }
 
@@ -371,31 +371,31 @@ WebRenderThreadPool::~WebRenderThreadPoo
   wr_thread_pool_delete(mThreadPool);
 }
 
 } // namespace wr
 } // namespace mozilla
 
 extern "C" {
 
-void wr_notifier_new_frame_ready(WrWindowId aWindowId)
+void wr_notifier_new_frame_ready(mozilla::wr::WrWindowId aWindowId)
 {
   mozilla::wr::RenderThread::Get()->IncPendingFrameCount(aWindowId);
   mozilla::wr::RenderThread::Get()->NewFrameReady(mozilla::wr::WindowId(aWindowId));
 }
 
-void wr_notifier_new_scroll_frame_ready(WrWindowId aWindowId, bool aCompositeNeeded)
+void wr_notifier_new_scroll_frame_ready(mozilla::wr::WrWindowId aWindowId, bool aCompositeNeeded)
 {
   // It is not necessary to update rendering with new_scroll_frame_ready.
   // WebRenderBridgeParent::CompositeToTarget() is implemented to call
   // WebRenderAPI::GenerateFrame() if it is necessary to trigger UpdateAndRender().
   // See Bug 1377688.
 }
 
-void wr_notifier_external_event(WrWindowId aWindowId, size_t aRawEvent)
+void wr_notifier_external_event(mozilla::wr::WrWindowId aWindowId, size_t aRawEvent)
 {
   mozilla::UniquePtr<mozilla::wr::RendererEvent> evt(
     reinterpret_cast<mozilla::wr::RendererEvent*>(aRawEvent));
   mozilla::wr::RenderThread::Get()->RunEvent(mozilla::wr::WindowId(aWindowId),
                                              mozilla::Move(evt));
 }
 
 } // extern C
--- a/gfx/webrender_bindings/RenderThread.h
+++ b/gfx/webrender_bindings/RenderThread.h
@@ -29,20 +29,20 @@ class RenderThread;
 
 /// A rayon thread pool that is shared by all WebRender instances within a process.
 class WebRenderThreadPool {
 public:
   WebRenderThreadPool();
 
   ~WebRenderThreadPool();
 
-  WrThreadPool* Raw() { return mThreadPool; }
+  wr::WrThreadPool* Raw() { return mThreadPool; }
 
 protected:
-  WrThreadPool* mThreadPool;
+  wr::WrThreadPool* mThreadPool;
 };
 
 
 /// Base class for an event that can be scheduled to run on the render thread.
 ///
 /// The event can be passed through the same channels as regular WebRender messages
 /// to preserve ordering.
 class RendererEvent
--- a/gfx/webrender_bindings/RendererOGL.cpp
+++ b/gfx/webrender_bindings/RendererOGL.cpp
@@ -11,17 +11,17 @@
 #include "mozilla/layers/CompositorThread.h"
 #include "mozilla/webrender/RenderBufferTextureHost.h"
 #include "mozilla/webrender/RenderTextureHostOGL.h"
 #include "mozilla/widget/CompositorWidget.h"
 
 namespace mozilla {
 namespace wr {
 
-WrExternalImage LockExternalImage(void* aObj, WrExternalImageId aId, uint8_t aChannelIndex)
+wr::WrExternalImage LockExternalImage(void* aObj, wr::WrExternalImageId aId, uint8_t aChannelIndex)
 {
   RendererOGL* renderer = reinterpret_cast<RendererOGL*>(aObj);
   RenderTextureHost* texture = renderer->GetRenderTexture(aId);
 
   if (texture->AsBufferTextureHost()) {
     RenderBufferTextureHost* bufferTexture = texture->AsBufferTextureHost();
     MOZ_ASSERT(bufferTexture);
     bufferTexture->Lock();
@@ -39,70 +39,70 @@ WrExternalImage LockExternalImage(void* 
     gfx::IntSize size = textureOGL->GetSize(aChannelIndex);
 
     return NativeTextureToWrExternalImage(textureOGL->GetGLHandle(aChannelIndex),
                                           0, 0,
                                           size.width, size.height);
   }
 }
 
-void UnlockExternalImage(void* aObj, WrExternalImageId aId, uint8_t aChannelIndex)
+void UnlockExternalImage(void* aObj, wr::WrExternalImageId aId, uint8_t aChannelIndex)
 {
   RendererOGL* renderer = reinterpret_cast<RendererOGL*>(aObj);
   RenderTextureHost* texture = renderer->GetRenderTexture(aId);
   MOZ_ASSERT(texture);
   texture->Unlock();
 }
 
 RendererOGL::RendererOGL(RefPtr<RenderThread>&& aThread,
                          RefPtr<gl::GLContext>&& aGL,
                          RefPtr<widget::CompositorWidget>&& aWidget,
                          wr::WindowId aWindowId,
-                         WrRenderer* aWrRenderer,
+                         wr::Renderer* aRenderer,
                          layers::CompositorBridgeParentBase* aBridge)
   : mThread(aThread)
   , mGL(aGL)
   , mWidget(aWidget)
-  , mWrRenderer(aWrRenderer)
+  , mRenderer(aRenderer)
   , mBridge(aBridge)
   , mWindowId(aWindowId)
 {
   MOZ_ASSERT(mThread);
   MOZ_ASSERT(mGL);
   MOZ_ASSERT(mWidget);
-  MOZ_ASSERT(mWrRenderer);
+  MOZ_ASSERT(mRenderer);
   MOZ_ASSERT(mBridge);
   MOZ_COUNT_CTOR(RendererOGL);
 }
 
 RendererOGL::~RendererOGL()
 {
   MOZ_COUNT_DTOR(RendererOGL);
   if (!mGL->MakeCurrent()) {
     gfxCriticalNote << "Failed to make render context current during destroying.";
     // Leak resources!
     return;
   }
-  wr_renderer_delete(mWrRenderer);
+  wr_renderer_delete(mRenderer);
 }
 
-WrExternalImageHandler
+wr::WrExternalImageHandler
 RendererOGL::GetExternalImageHandler()
 {
-  return WrExternalImageHandler {
+  return wr::WrExternalImageHandler {
     this,
     LockExternalImage,
     UnlockExternalImage,
   };
 }
 
 void
 RendererOGL::Update()
 {
-  wr_renderer_update(mWrRenderer);
+  wr_renderer_update(mRenderer);
 }
 
 bool
 RendererOGL::Render()
 {
   if (!mGL->MakeCurrent()) {
     gfxCriticalNote << "Failed to make render context current, can't draw.";
     // XXX This could cause oom in webrender since pending_texture_updates is not handled.
@@ -122,17 +122,17 @@ RendererOGL::Render()
   if (!mWidget->PreRender(&widgetContext)) {
     // XXX This could cause oom in webrender since pending_texture_updates is not handled.
     // It needs to be addressed.
     return false;
   }
   // XXX set clear color if MOZ_WIDGET_ANDROID is defined.
 
   auto size = mWidget->GetClientSize();
-  wr_renderer_render(mWrRenderer, size.width, size.height);
+  wr_renderer_render(mRenderer, size.width, size.height);
 
   mGL->SwapBuffers();
   mWidget->PostRender(&widgetContext);
 
   // TODO: Flush pending actions such as texture deletions/unlocks and
   //       textureHosts recycling.
 
   return true;
@@ -162,25 +162,25 @@ RendererOGL::Resume()
 #else
   return true;
 #endif
 }
 
 void
 RendererOGL::SetProfilerEnabled(bool aEnabled)
 {
-  wr_renderer_set_profiler_enabled(mWrRenderer, aEnabled);
+  wr_renderer_set_profiler_enabled(mRenderer, aEnabled);
 }
 
-WrRenderedEpochs*
+wr::WrRenderedEpochs*
 RendererOGL::FlushRenderedEpochs()
 {
-  return wr_renderer_flush_rendered_epochs(mWrRenderer);
+  return wr_renderer_flush_rendered_epochs(mRenderer);
 }
 
 RenderTextureHost*
-RendererOGL::GetRenderTexture(WrExternalImageId aExternalImageId)
+RendererOGL::GetRenderTexture(wr::WrExternalImageId aExternalImageId)
 {
   return mThread->GetRenderTexture(aExternalImageId);
 }
 
 } // namespace wr
 } // namespace mozilla
--- a/gfx/webrender_bindings/RendererOGL.h
+++ b/gfx/webrender_bindings/RendererOGL.h
@@ -35,21 +35,21 @@ class RenderTextureHost;
 
 /// Owns the WebRender renderer and GL context.
 ///
 /// There is one renderer per window, all owned by the render thread.
 /// This class is a similar abstraction to CompositorOGL except that it is used
 /// on the render thread instead of the compositor thread.
 class RendererOGL
 {
-  friend WrExternalImage LockExternalImage(void* aObj, WrExternalImageId aId, uint8_t aChannelIndex);
-  friend void UnlockExternalImage(void* aObj, WrExternalImageId aId, uint8_t aChannelIndex);
+  friend wr::WrExternalImage LockExternalImage(void* aObj, wr::WrExternalImageId aId, uint8_t aChannelIndex);
+  friend void UnlockExternalImage(void* aObj, wr::WrExternalImageId aId, uint8_t aChannelIndex);
 
 public:
-  WrExternalImageHandler GetExternalImageHandler();
+  wr::WrExternalImageHandler GetExternalImageHandler();
 
   /// This can be called on the render thread only.
   void Update();
 
   /// This can be called on the render thread only.
   bool Render();
 
   /// This can be called on the render thread only.
@@ -61,39 +61,39 @@ public:
   /// This can be called on the render thread only.
   ~RendererOGL();
 
   /// This can be called on the render thread only.
   RendererOGL(RefPtr<RenderThread>&& aThread,
               RefPtr<gl::GLContext>&& aGL,
               RefPtr<widget::CompositorWidget>&&,
               wr::WindowId aWindowId,
-              WrRenderer* aWrRenderer,
+              wr::Renderer* aRenderer,
               layers::CompositorBridgeParentBase* aBridge);
 
   /// This can be called on the render thread only.
   void Pause();
 
   /// This can be called on the render thread only.
   bool Resume();
 
   layers::CompositorBridgeParentBase* GetCompositorBridge() { return mBridge; }
 
-  WrRenderedEpochs* FlushRenderedEpochs();
+  wr::WrRenderedEpochs* FlushRenderedEpochs();
 
-  RenderTextureHost* GetRenderTexture(WrExternalImageId aExternalImageId);
+  RenderTextureHost* GetRenderTexture(wr::WrExternalImageId aExternalImageId);
 
-  WrRenderer* GetWrRenderer() { return mWrRenderer; }
+  wr::Renderer* GetRenderer() { return mRenderer; }
 
 protected:
 
   RefPtr<RenderThread> mThread;
   RefPtr<gl::GLContext> mGL;
   RefPtr<widget::CompositorWidget> mWidget;
-  WrRenderer* mWrRenderer;
+  wr::Renderer* mRenderer;
   layers::CompositorBridgeParentBase* mBridge;
   wr::WindowId mWindowId;
 };
 
 } // namespace wr
 } // namespace mozilla
 
 #endif
--- a/gfx/webrender_bindings/WebRenderAPI.cpp
+++ b/gfx/webrender_bindings/WebRenderAPI.cpp
@@ -18,24 +18,24 @@
 namespace mozilla {
 namespace wr {
 
 using layers::Stringify;
 
 class NewRenderer : public RendererEvent
 {
 public:
-  NewRenderer(WrAPI** aApi, layers::CompositorBridgeParentBase* aBridge,
+  NewRenderer(wr::RenderApi** aApi, layers::CompositorBridgeParentBase* aBridge,
               GLint* aMaxTextureSize,
               bool* aUseANGLE,
               RefPtr<widget::CompositorWidget>&& aWidget,
               layers::SynchronousTask* aTask,
               bool aEnableProfiler,
               LayoutDeviceIntSize aSize)
-    : mWrApi(aApi)
+    : mRenderApi(aApi)
     , mMaxTextureSize(aMaxTextureSize)
     , mUseANGLE(aUseANGLE)
     , mBridge(aBridge)
     , mCompositorWidget(Move(aWidget))
     , mTask(aTask)
     , mEnableProfiler(aEnableProfiler)
     , mSize(aSize)
   {
@@ -65,42 +65,42 @@ public:
     if (!gl || !gl->MakeCurrent()) {
       gfxCriticalNote << "Failed GL context creation for WebRender: " << gfx::hexa(gl.get());
       return;
     }
 
     gl->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, mMaxTextureSize);
     *mUseANGLE = gl->IsANGLE();
 
-    WrRenderer* wrRenderer = nullptr;
+    wr::Renderer* wrRenderer = nullptr;
     if (!wr_window_new(aWindowId, mSize.width, mSize.height, gl.get(),
                        aRenderThread.ThreadPool().Raw(),
-                       this->mEnableProfiler, mWrApi, &wrRenderer)) {
+                       this->mEnableProfiler, mRenderApi, &wrRenderer)) {
       // wr_window_new puts a message into gfxCriticalNote if it returns false
       return;
     }
     MOZ_ASSERT(wrRenderer);
 
     RefPtr<RenderThread> thread = &aRenderThread;
     auto renderer = MakeUnique<RendererOGL>(Move(thread),
                                             Move(gl),
                                             Move(mCompositorWidget),
                                             aWindowId,
                                             wrRenderer,
                                             mBridge);
     if (wrRenderer && renderer) {
-      WrExternalImageHandler handler = renderer->GetExternalImageHandler();
+      wr::WrExternalImageHandler handler = renderer->GetExternalImageHandler();
       wr_renderer_set_external_image_handler(wrRenderer, &handler);
     }
 
     aRenderThread.AddRenderer(aWindowId, Move(renderer));
   }
 
 private:
-  WrAPI** mWrApi;
+  wr::RenderApi** mRenderApi;
   GLint* mMaxTextureSize;
   bool* mUseANGLE;
   layers::CompositorBridgeParentBase* mBridge;
   RefPtr<widget::CompositorWidget> mCompositorWidget;
   layers::SynchronousTask* mTask;
   bool mEnableProfiler;
   LayoutDeviceIntSize mSize;
 };
@@ -138,111 +138,111 @@ WebRenderAPI::Create(bool aEnableProfile
                      LayoutDeviceIntSize aSize)
 {
   MOZ_ASSERT(aBridge);
   MOZ_ASSERT(aWidget);
 
   static uint64_t sNextId = 1;
   auto id = NewWindowId(sNextId++);
 
-  WrAPI* wrApi = nullptr;
+  wr::RenderApi* renderApi = nullptr;
   GLint maxTextureSize = 0;
   bool useANGLE = false;
 
-  // Dispatch a synchronous task because the WrApi object needs to be created
+  // Dispatch a synchronous task because the RenderApi object needs to be created
   // on the render thread. If need be we could delay waiting on this task until
-  // the next time we need to access the WrApi object.
+  // the next time we need to access the RenderApi object.
   layers::SynchronousTask task("Create Renderer");
-  auto event = MakeUnique<NewRenderer>(&wrApi, aBridge, &maxTextureSize, &useANGLE,
+  auto event = MakeUnique<NewRenderer>(&renderApi, aBridge, &maxTextureSize, &useANGLE,
                                        Move(aWidget), &task, aEnableProfiler, aSize);
   RenderThread::Get()->RunEvent(id, Move(event));
 
   task.Wait();
 
-  if (!wrApi) {
+  if (!renderApi) {
     return nullptr;
   }
 
-  return RefPtr<WebRenderAPI>(new WebRenderAPI(wrApi, id, maxTextureSize, useANGLE)).forget();
+  return RefPtr<WebRenderAPI>(new WebRenderAPI(renderApi, id, maxTextureSize, useANGLE)).forget();
 }
 
-WrIdNamespace
+wr::WrIdNamespace
 WebRenderAPI::GetNamespace() {
-  return wr_api_get_namespace(mWrApi);
+  return wr_api_get_namespace(mRenderApi);
 }
 
 WebRenderAPI::~WebRenderAPI()
 {
   layers::SynchronousTask task("Destroy WebRenderAPI");
   auto event = MakeUnique<RemoveRenderer>(&task);
   RunOnRenderThread(Move(event));
   task.Wait();
 
-  wr_api_delete(mWrApi);
+  wr_api_delete(mRenderApi);
 }
 
 void
-WebRenderAPI::UpdateScrollPosition(const WrPipelineId& aPipelineId,
+WebRenderAPI::UpdateScrollPosition(const wr::WrPipelineId& aPipelineId,
                                    const layers::FrameMetrics::ViewID& aScrollId,
-                                   const WrPoint& aScrollPosition)
+                                   const wr::LayoutPoint& aScrollPosition)
 {
-  wr_scroll_layer_with_id(mWrApi, aPipelineId, aScrollId, aScrollPosition);
+  wr_scroll_layer_with_id(mRenderApi, aPipelineId, aScrollId, aScrollPosition);
 }
 
 void
 WebRenderAPI::GenerateFrame()
 {
-  wr_api_generate_frame(mWrApi);
+  wr_api_generate_frame(mRenderApi);
 }
 
 void
-WebRenderAPI::GenerateFrame(const nsTArray<WrOpacityProperty>& aOpacityArray,
-                            const nsTArray<WrTransformProperty>& aTransformArray)
+WebRenderAPI::GenerateFrame(const nsTArray<wr::WrOpacityProperty>& aOpacityArray,
+                            const nsTArray<wr::WrTransformProperty>& aTransformArray)
 {
-  wr_api_generate_frame_with_properties(mWrApi,
+  wr_api_generate_frame_with_properties(mRenderApi,
                                         aOpacityArray.IsEmpty() ?
                                           nullptr : aOpacityArray.Elements(),
                                         aOpacityArray.Length(),
                                         aTransformArray.IsEmpty() ?
                                           nullptr : aTransformArray.Elements(),
                                         aTransformArray.Length());
 }
 
 void
 WebRenderAPI::SetRootDisplayList(gfx::Color aBgColor,
                                  Epoch aEpoch,
                                  LayerSize aViewportSize,
-                                 WrPipelineId pipeline_id,
-                                 const WrSize& content_size,
-                                 WrBuiltDisplayListDescriptor dl_descriptor,
+                                 wr::WrPipelineId pipeline_id,
+                                 const LayoutSize& content_size,
+                                 wr::BuiltDisplayListDescriptor dl_descriptor,
                                  uint8_t *dl_data,
                                  size_t dl_size)
 {
-    wr_api_set_root_display_list(mWrApi,
-                                 ToWrColor(aBgColor),
+    wr_api_set_root_display_list(mRenderApi,
+                                 ToColorF(aBgColor),
                                  aEpoch,
                                  aViewportSize.width, aViewportSize.height,
                                  pipeline_id,
                                  content_size,
                                  dl_descriptor,
                                  dl_data,
                                  dl_size);
 }
 
 void
 WebRenderAPI::ClearRootDisplayList(Epoch aEpoch,
-                                   WrPipelineId pipeline_id)
+                                   wr::WrPipelineId pipeline_id)
 {
-  wr_api_clear_root_display_list(mWrApi, aEpoch, pipeline_id);
+  wr_api_clear_root_display_list(mRenderApi, aEpoch, pipeline_id);
 }
 
 void
 WebRenderAPI::SetWindowParameters(LayoutDeviceIntSize size)
 {
-  wr_api_set_window_parameters(mWrApi, size.width, size.height);
+  wr_api_set_window_parameters(mRenderApi, size.width, size.height);
 }
 
 void
 WebRenderAPI::Readback(gfx::IntSize size,
                        uint8_t *buffer,
                        uint32_t buffer_size)
 {
     class Readback : public RendererEvent
@@ -261,17 +261,17 @@ WebRenderAPI::Readback(gfx::IntSize size
             ~Readback()
             {
                 MOZ_COUNT_DTOR(Readback);
             }
 
             virtual void Run(RenderThread& aRenderThread, WindowId aWindowId) override
             {
                 aRenderThread.UpdateAndRender(aWindowId);
-                wr_renderer_readback(aRenderThread.GetRenderer(aWindowId)->GetWrRenderer(),
+                wr_renderer_readback(aRenderThread.GetRenderer(aWindowId)->GetRenderer(),
                                      mSize.width, mSize.height, mBuffer, mBufferSize);
                 layers::AutoCompleteTask complete(mTask);
             }
 
             layers::SynchronousTask* mTask;
             gfx::IntSize mSize;
             uint8_t *mBuffer;
             uint32_t mBufferSize;
@@ -394,92 +394,92 @@ WebRenderAPI::WaitFlushed()
     RunOnRenderThread(Move(event));
 
     task.Wait();
 }
 
 void
 WebRenderAPI::SetRootPipeline(PipelineId aPipeline)
 {
-  wr_api_set_root_pipeline(mWrApi, aPipeline);
+  wr_api_set_root_pipeline(mRenderApi, aPipeline);
 }
 
 void
 WebRenderAPI::AddImage(ImageKey key, const ImageDescriptor& aDescriptor,
                        Range<uint8_t> aBytes)
 {
-  wr_api_add_image(mWrApi,
+  wr_api_add_image(mRenderApi,
                    key,
                    &aDescriptor,
                    RangeToByteSlice(aBytes));
 }
 
 void
 WebRenderAPI::AddBlobImage(ImageKey key, const ImageDescriptor& aDescriptor,
                            Range<uint8_t> aBytes)
 {
-  wr_api_add_blob_image(mWrApi,
+  wr_api_add_blob_image(mRenderApi,
                         key,
                         &aDescriptor,
                         RangeToByteSlice(aBytes));
 }
 
 void
 WebRenderAPI::AddExternalImage(ImageKey key,
                                const ImageDescriptor& aDescriptor,
                                ExternalImageId aExtID,
-                               WrExternalImageBufferType aBufferType,
+                               wr::WrExternalImageBufferType aBufferType,
                                uint8_t aChannelIndex)
 {
-  wr_api_add_external_image(mWrApi,
+  wr_api_add_external_image(mRenderApi,
                             key,
                             &aDescriptor,
                             aExtID,
                             aBufferType,
                             aChannelIndex);
 }
 
 void
 WebRenderAPI::AddExternalImageBuffer(ImageKey key,
                                      const ImageDescriptor& aDescriptor,
                                      ExternalImageId aHandle)
 {
-  wr_api_add_external_image_buffer(mWrApi,
+  wr_api_add_external_image_buffer(mRenderApi,
                                    key,
                                    &aDescriptor,
                                    aHandle);
 }
 
 void
 WebRenderAPI::UpdateImageBuffer(ImageKey aKey,
                                 const ImageDescriptor& aDescriptor,
                                 Range<uint8_t> aBytes)
 {
-  wr_api_update_image(mWrApi,
+  wr_api_update_image(mRenderApi,
                       aKey,
                       &aDescriptor,
                       RangeToByteSlice(aBytes));
 }
 
 void
 WebRenderAPI::DeleteImage(ImageKey aKey)
 {
-  wr_api_delete_image(mWrApi, aKey);
+  wr_api_delete_image(mRenderApi, aKey);
 }
 
 void
 WebRenderAPI::AddRawFont(wr::FontKey aKey, Range<uint8_t> aBytes, uint32_t aIndex)
 {
-  wr_api_add_raw_font(mWrApi, aKey, &aBytes[0], aBytes.length(), aIndex);
+  wr_api_add_raw_font(mRenderApi, aKey, &aBytes[0], aBytes.length(), aIndex);
 }
 
 void
 WebRenderAPI::DeleteFont(wr::FontKey aKey)
 {
-  wr_api_delete_font(mWrApi, aKey);
+  wr_api_delete_font(mRenderApi, aKey);
 }
 
 class EnableProfiler : public RendererEvent
 {
 public:
   explicit EnableProfiler(bool aEnabled)
     : mEnabled(aEnabled)
   {
@@ -509,21 +509,21 @@ WebRenderAPI::SetProfilerEnabled(bool aE
   auto event = MakeUnique<EnableProfiler>(aEnabled);
   RunOnRenderThread(Move(event));
 }
 
 void
 WebRenderAPI::RunOnRenderThread(UniquePtr<RendererEvent> aEvent)
 {
   auto event = reinterpret_cast<uintptr_t>(aEvent.release());
-  wr_api_send_external_event(mWrApi, event);
+  wr_api_send_external_event(mRenderApi, event);
 }
 
 DisplayListBuilder::DisplayListBuilder(PipelineId aId,
-                                       const WrSize& aContentSize)
+                                       const wr::LayoutSize& aContentSize)
 {
   MOZ_COUNT_CTOR(DisplayListBuilder);
   mWrState = wr_state_new(aId, aContentSize);
 }
 
 DisplayListBuilder::~DisplayListBuilder()
 {
   MOZ_COUNT_DTOR(DisplayListBuilder);
@@ -538,62 +538,62 @@ DisplayListBuilder::Begin(const LayerInt
 
 void
 DisplayListBuilder::End()
 {
   wr_dp_end(mWrState);
 }
 
 void
-DisplayListBuilder::Finalize(WrSize& aOutContentSize,
+DisplayListBuilder::Finalize(wr::LayoutSize& aOutContentSize,
                              BuiltDisplayList& aOutDisplayList)
 {
   wr_api_finalize_builder(mWrState,
                           &aOutContentSize,
                           &aOutDisplayList.dl_desc,
                           &aOutDisplayList.dl.inner);
 }
 
 void
-DisplayListBuilder::PushStackingContext(const WrRect& aBounds,
+DisplayListBuilder::PushStackingContext(const wr::LayoutRect& aBounds,
                                         const uint64_t& aAnimationId,
                                         const float* aOpacity,
                                         const gfx::Matrix4x4* aTransform,
-                                        WrTransformStyle aTransformStyle,
-                                        const WrMixBlendMode& aMixBlendMode,
-                                        const nsTArray<WrFilterOp>& aFilters)
+                                        wr::TransformStyle aTransformStyle,
+                                        const wr::MixBlendMode& aMixBlendMode,
+                                        const nsTArray<wr::WrFilterOp>& aFilters)
 {
-  WrMatrix matrix;
+  wr::LayoutTransform matrix;
   if (aTransform) {
-    matrix = ToWrMatrix(*aTransform);
+    matrix = ToLayoutTransform(*aTransform);
   }
-  const WrMatrix* maybeTransform = aTransform ? &matrix : nullptr;
+  const wr::LayoutTransform* maybeTransform = aTransform ? &matrix : nullptr;
   WRDL_LOG("PushStackingContext b=%s t=%s\n", Stringify(aBounds).c_str(),
       aTransform ? Stringify(*aTransform).c_str() : "none");
   wr_dp_push_stacking_context(mWrState, aBounds, aAnimationId, aOpacity,
                               maybeTransform, aTransformStyle, aMixBlendMode,
                               aFilters.Elements(), aFilters.Length());
 }
 
 void
 DisplayListBuilder::PopStackingContext()
 {
   WRDL_LOG("PopStackingContext\n");
   wr_dp_pop_stacking_context(mWrState);
 }
 
 void
-DisplayListBuilder::PushClip(const WrRect& aClipRect,
-                             const WrImageMask* aMask)
+DisplayListBuilder::PushClip(const wr::LayoutRect& aClipRect,
+                             const wr::WrImageMask* aMask)
 {
   uint64_t clip_id = wr_dp_push_clip(mWrState, aClipRect, nullptr, 0, aMask);
   WRDL_LOG("PushClip id=%" PRIu64 " r=%s m=%p b=%s\n", clip_id,
       Stringify(aClipRect).c_str(), aMask,
       aMask ? Stringify(aMask->rect).c_str() : "none");
-  mClipIdStack.push_back(WrClipId { clip_id });
+  mClipIdStack.push_back(wr::WrClipId { clip_id });
 }
 
 void
 DisplayListBuilder::PopClip()
 {
   WRDL_LOG("PopClip id=%" PRIu64 "\n", mClipIdStack.back().id);
   mClipIdStack.pop_back();
   wr_dp_pop_clip(mWrState);
@@ -604,18 +604,18 @@ DisplayListBuilder::PushBuiltDisplayList
 {
   wr_dp_push_built_display_list(mWrState,
                                 dl.dl_desc,
                                 &dl.dl.inner);
 }
 
 void
 DisplayListBuilder::PushScrollLayer(const layers::FrameMetrics::ViewID& aScrollId,
-                                    const WrRect& aContentRect,
-                                    const WrRect& aClipRect)
+                                    const wr::LayoutRect& aContentRect,
+                                    const wr::LayoutRect& aClipRect)
 {
   WRDL_LOG("PushScrollLayer id=%" PRIu64 " co=%s cl=%s\n",
       aScrollId, Stringify(aContentRect).c_str(), Stringify(aClipRect).c_str());
   wr_dp_push_scroll_layer(mWrState, aScrollId, aContentRect, aClipRect);
   if (!mScrollIdStack.empty()) {
     auto it = mScrollParents.insert({aScrollId, mScrollIdStack.back()});
     if (!it.second) { // aScrollId was already a key in mScrollParents
                       // so check that the parent value is the same.
@@ -630,258 +630,258 @@ DisplayListBuilder::PopScrollLayer()
 {
   WRDL_LOG("PopScrollLayer id=%" PRIu64 "\n", mScrollIdStack.back());
   mScrollIdStack.pop_back();
   wr_dp_pop_scroll_layer(mWrState);
 }
 
 void
 DisplayListBuilder::PushClipAndScrollInfo(const layers::FrameMetrics::ViewID& aScrollId,
-                                          const WrClipId* aClipId)
+                                          const wr::WrClipId* aClipId)
 {
   WRDL_LOG("PushClipAndScroll s=%" PRIu64 " c=%s\n", aScrollId,
       aClipId ? Stringify(aClipId->id).c_str() : "none");
   wr_dp_push_clip_and_scroll_info(mWrState, aScrollId,
       aClipId ? &(aClipId->id) : nullptr);
 }
 
 void
 DisplayListBuilder::PopClipAndScrollInfo()
 {
   WRDL_LOG("PopClipAndScroll\n");
   wr_dp_pop_clip_and_scroll_info(mWrState);
 }
 
 void
-DisplayListBuilder::PushRect(const WrRect& aBounds,
-                             const WrRect& aClip,
-                             const WrColor& aColor)
+DisplayListBuilder::PushRect(const wr::LayoutRect& aBounds,
+                             const wr::LayoutRect& aClip,
+                             const wr::ColorF& aColor)
 {
   WRDL_LOG("PushRect b=%s cl=%s c=%s\n",
       Stringify(aBounds).c_str(),
       Stringify(aClip).c_str(),
       Stringify(aColor).c_str());
   wr_dp_push_rect(mWrState, aBounds, aClip, aColor);
 }
 
 void
-DisplayListBuilder::PushLinearGradient(const WrRect& aBounds,
-                                       const WrRect& aClip,
-                                       const WrPoint& aStartPoint,
-                                       const WrPoint& aEndPoint,
-                                       const nsTArray<WrGradientStop>& aStops,
-                                       wr::GradientExtendMode aExtendMode,
-                                       const WrSize aTileSize,
-                                       const WrSize aTileSpacing)
+DisplayListBuilder::PushLinearGradient(const wr::LayoutRect& aBounds,
+                                       const wr::LayoutRect& aClip,
+                                       const wr::LayoutPoint& aStartPoint,
+                                       const wr::LayoutPoint& aEndPoint,
+                                       const nsTArray<wr::GradientStop>& aStops,
+                                       wr::ExtendMode aExtendMode,
+                                       const wr::LayoutSize aTileSize,
+                                       const wr::LayoutSize aTileSpacing)
 {
   wr_dp_push_linear_gradient(mWrState,
                              aBounds, aClip,
                              aStartPoint, aEndPoint,
                              aStops.Elements(), aStops.Length(),
                              aExtendMode,
                              aTileSize, aTileSpacing);
 }
 
 void
-DisplayListBuilder::PushRadialGradient(const WrRect& aBounds,
-                                       const WrRect& aClip,
-                                       const WrPoint& aCenter,
-                                       const WrSize& aRadius,
-                                       const nsTArray<WrGradientStop>& aStops,
-                                       wr::GradientExtendMode aExtendMode,
-                                       const WrSize aTileSize,
-                                       const WrSize aTileSpacing)
+DisplayListBuilder::PushRadialGradient(const wr::LayoutRect& aBounds,
+                                       const wr::LayoutRect& aClip,
+                                       const wr::LayoutPoint& aCenter,
+                                       const wr::LayoutSize& aRadius,
+                                       const nsTArray<wr::GradientStop>& aStops,
+                                       wr::ExtendMode aExtendMode,
+                                       const wr::LayoutSize aTileSize,
+                                       const wr::LayoutSize aTileSpacing)
 {
   wr_dp_push_radial_gradient(mWrState,
                              aBounds, aClip,
                              aCenter, aRadius,
                              aStops.Elements(), aStops.Length(),
                              aExtendMode,
                              aTileSize, aTileSpacing);
 }
 
 void
-DisplayListBuilder::PushImage(const WrRect& aBounds,
-                              const WrRect& aClip,
+DisplayListBuilder::PushImage(const wr::LayoutRect& aBounds,
+                              const wr::LayoutRect& aClip,
                               wr::ImageRendering aFilter,
                               wr::ImageKey aImage)
 {
-  WrSize size;
-  size.width = aBounds.width;
-  size.height = aBounds.height;
+  wr::LayoutSize size;
+  size.width = aBounds.size.width;
+  size.height = aBounds.size.height;
   PushImage(aBounds, aClip, size, size, aFilter, aImage);
 }
 
 void
-DisplayListBuilder::PushImage(const WrRect& aBounds,
-                              const WrRect& aClip,
-                              const WrSize& aStretchSize,
-                              const WrSize& aTileSpacing,
+DisplayListBuilder::PushImage(const wr::LayoutRect& aBounds,
+                              const wr::LayoutRect& aClip,
+                              const wr::LayoutSize& aStretchSize,
+                              const wr::LayoutSize& aTileSpacing,
                               wr::ImageRendering aFilter,
                               wr::ImageKey aImage)
 {
   WRDL_LOG("PushImage b=%s cl=%s s=%s t=%s\n", Stringify(aBounds).c_str(),
       Stringify(aClip).c_str(), Stringify(aStretchSize).c_str(),
       Stringify(aTileSpacing).c_str());
   wr_dp_push_image(mWrState, aBounds, aClip, aStretchSize, aTileSpacing, aFilter, aImage);
 }
 
 void
-DisplayListBuilder::PushYCbCrPlanarImage(const WrRect& aBounds,
-                                         const WrRect& aClip,
+DisplayListBuilder::PushYCbCrPlanarImage(const wr::LayoutRect& aBounds,
+                                         const wr::LayoutRect& aClip,
                                          wr::ImageKey aImageChannel0,
                                          wr::ImageKey aImageChannel1,
                                          wr::ImageKey aImageChannel2,
-                                         WrYuvColorSpace aColorSpace,
+                                         wr::WrYuvColorSpace aColorSpace,
                                          wr::ImageRendering aRendering)
 {
   wr_dp_push_yuv_planar_image(mWrState,
                               aBounds,
                               aClip,
                               aImageChannel0,
                               aImageChannel1,
                               aImageChannel2,
                               aColorSpace,
                               aRendering);
 }
 
 void
-DisplayListBuilder::PushNV12Image(const WrRect& aBounds,
-                                  const WrRect& aClip,
+DisplayListBuilder::PushNV12Image(const wr::LayoutRect& aBounds,
+                                  const wr::LayoutRect& aClip,
                                   wr::ImageKey aImageChannel0,
                                   wr::ImageKey aImageChannel1,
-                                  WrYuvColorSpace aColorSpace,
+                                  wr::WrYuvColorSpace aColorSpace,
                                   wr::ImageRendering aRendering)
 {
   wr_dp_push_yuv_NV12_image(mWrState,
                             aBounds,
                             aClip,
                             aImageChannel0,
                             aImageChannel1,
                             aColorSpace,
                             aRendering);
 }
 
 void
-DisplayListBuilder::PushYCbCrInterleavedImage(const WrRect& aBounds,
-                                              const WrRect& aClip,
+DisplayListBuilder::PushYCbCrInterleavedImage(const wr::LayoutRect& aBounds,
+                                              const wr::LayoutRect& aClip,
                                               wr::ImageKey aImageChannel0,
-                                              WrYuvColorSpace aColorSpace,
+                                              wr::WrYuvColorSpace aColorSpace,
                                               wr::ImageRendering aRendering)
 {
   wr_dp_push_yuv_interleaved_image(mWrState,
                                    aBounds,
                                    aClip,
                                    aImageChannel0,
                                    aColorSpace,
                                    aRendering);
 }
 
 void
-DisplayListBuilder::PushIFrame(const WrRect& aBounds,
+DisplayListBuilder::PushIFrame(const wr::LayoutRect& aBounds,
                                PipelineId aPipeline)
 {
   wr_dp_push_iframe(mWrState, aBounds, aPipeline);
 }
 
 void
-DisplayListBuilder::PushBorder(const WrRect& aBounds,
-                               const WrRect& aClip,
-                               const WrBorderWidths& aWidths,
-                               const Range<const WrBorderSide>& aSides,
-                               const WrBorderRadius& aRadius)
+DisplayListBuilder::PushBorder(const wr::LayoutRect& aBounds,
+                               const wr::LayoutRect& aClip,
+                               const wr::BorderWidths& aWidths,
+                               const Range<const wr::BorderSide>& aSides,
+                               const wr::BorderRadius& aRadius)
 {
   MOZ_ASSERT(aSides.length() == 4);
   if (aSides.length() != 4) {
     return;
   }
   wr_dp_push_border(mWrState, aBounds, aClip,
                     aWidths, aSides[0], aSides[1], aSides[2], aSides[3], aRadius);
 }
 
 void
-DisplayListBuilder::PushBorderImage(const WrRect& aBounds,
-                                    const WrRect& aClip,
-                                    const WrBorderWidths& aWidths,
+DisplayListBuilder::PushBorderImage(const wr::LayoutRect& aBounds,
+                                    const wr::LayoutRect& aClip,
+                                    const wr::BorderWidths& aWidths,
                                     wr::ImageKey aImage,
-                                    const WrNinePatchDescriptor& aPatch,
-                                    const WrSideOffsets2Df32& aOutset,
-                                    const WrRepeatMode& aRepeatHorizontal,
-                                    const WrRepeatMode& aRepeatVertical)
+                                    const wr::NinePatchDescriptor& aPatch,
+                                    const wr::SideOffsets2D_f32& aOutset,
+                                    const wr::RepeatMode& aRepeatHorizontal,
+                                    const wr::RepeatMode& aRepeatVertical)
 {
   wr_dp_push_border_image(mWrState, aBounds, aClip,
                           aWidths, aImage, aPatch, aOutset,
                           aRepeatHorizontal, aRepeatVertical);
 }
 
 void
-DisplayListBuilder::PushBorderGradient(const WrRect& aBounds,
-                                       const WrRect& aClip,
-                                       const WrBorderWidths& aWidths,
-                                       const WrPoint& aStartPoint,
-                                       const WrPoint& aEndPoint,
-                                       const nsTArray<WrGradientStop>& aStops,
-                                       wr::GradientExtendMode aExtendMode,
-                                       const WrSideOffsets2Df32& aOutset)
+DisplayListBuilder::PushBorderGradient(const wr::LayoutRect& aBounds,
+                                       const wr::LayoutRect& aClip,
+                                       const wr::BorderWidths& aWidths,
+                                       const wr::LayoutPoint& aStartPoint,
+                                       const wr::LayoutPoint& aEndPoint,
+                                       const nsTArray<wr::GradientStop>& aStops,
+                                       wr::ExtendMode aExtendMode,
+                                       const wr::SideOffsets2D_f32& aOutset)
 {
   wr_dp_push_border_gradient(mWrState, aBounds, aClip,
                              aWidths, aStartPoint, aEndPoint,
                              aStops.Elements(), aStops.Length(),
                              aExtendMode, aOutset);
 }
 
 void
-DisplayListBuilder::PushBorderRadialGradient(const WrRect& aBounds,
-                                             const WrRect& aClip,
-                                             const WrBorderWidths& aWidths,
-                                             const WrPoint& aCenter,
-                                             const WrSize& aRadius,
-                                             const nsTArray<WrGradientStop>& aStops,
-                                             wr::GradientExtendMode aExtendMode,
-                                             const WrSideOffsets2Df32& aOutset)
+DisplayListBuilder::PushBorderRadialGradient(const wr::LayoutRect& aBounds,
+                                             const wr::LayoutRect& aClip,
+                                             const wr::BorderWidths& aWidths,
+                                             const wr::LayoutPoint& aCenter,
+                                             const wr::LayoutSize& aRadius,
+                                             const nsTArray<wr::GradientStop>& aStops,
+                                             wr::ExtendMode aExtendMode,
+                                             const wr::SideOffsets2D_f32& aOutset)
 {
   wr_dp_push_border_radial_gradient(
     mWrState, aBounds, aClip, aWidths, aCenter,
     aRadius, aStops.Elements(), aStops.Length(),
     aExtendMode, aOutset);
 }
 
 void
-DisplayListBuilder::PushText(const WrRect& aBounds,
-                             const WrRect& aClip,
+DisplayListBuilder::PushText(const wr::LayoutRect& aBounds,
+                             const wr::LayoutRect& aClip,
                              const gfx::Color& aColor,
                              wr::FontKey aFontKey,
-                             Range<const WrGlyphInstance> aGlyphBuffer,
+                             Range<const wr::GlyphInstance> aGlyphBuffer,
                              float aGlyphSize)
 {
   wr_dp_push_text(mWrState, aBounds, aClip,
-                  ToWrColor(aColor),
+                  ToColorF(aColor),
                   aFontKey,
                   &aGlyphBuffer[0], aGlyphBuffer.length(),
                   aGlyphSize);
 }
 
 void
-DisplayListBuilder::PushBoxShadow(const WrRect& aRect,
-                                  const WrRect& aClip,
-                                  const WrRect& aBoxBounds,
-                                  const WrPoint& aOffset,
-                                  const WrColor& aColor,
+DisplayListBuilder::PushBoxShadow(const wr::LayoutRect& aRect,
+                                  const wr::LayoutRect& aClip,
+                                  const wr::LayoutRect& aBoxBounds,
+                                  const wr::LayoutVector2D& aOffset,
+                                  const wr::ColorF& aColor,
                                   const float& aBlurRadius,
                                   const float& aSpreadRadius,
                                   const float& aBorderRadius,
-                                  const WrBoxShadowClipMode& aClipMode)
+                                  const wr::BoxShadowClipMode& aClipMode)
 {
   wr_dp_push_box_shadow(mWrState, aRect, aClip,
                         aBoxBounds, aOffset, aColor,
                         aBlurRadius, aSpreadRadius, aBorderRadius,
                         aClipMode);
 }
 
-Maybe<WrClipId>
+Maybe<wr::WrClipId>
 DisplayListBuilder::TopmostClipId()
 {
   if (mClipIdStack.empty()) {
     return Nothing();
   }
   return Some(mClipIdStack.back());
 }
 
--- a/gfx/webrender_bindings/WebRenderAPI.h
+++ b/gfx/webrender_bindings/WebRenderAPI.h
@@ -43,36 +43,36 @@ public:
   /// This can be called on the compositor thread only.
   static already_AddRefed<WebRenderAPI> Create(bool aEnableProfiler,
                                                layers::CompositorBridgeParentBase* aBridge,
                                                RefPtr<widget::CompositorWidget>&& aWidget,
                                                LayoutDeviceIntSize aSize);
 
   wr::WindowId GetId() const { return mId; }
 
-  void UpdateScrollPosition(const WrPipelineId& aPipelineId,
+  void UpdateScrollPosition(const wr::WrPipelineId& aPipelineId,
                             const layers::FrameMetrics::ViewID& aScrollId,
-                            const WrPoint& aScrollPosition);
+                            const wr::LayoutPoint& aScrollPosition);
 
   void GenerateFrame();
-  void GenerateFrame(const nsTArray<WrOpacityProperty>& aOpacityArray,
-                     const nsTArray<WrTransformProperty>& aTransformArray);
+  void GenerateFrame(const nsTArray<wr::WrOpacityProperty>& aOpacityArray,
+                     const nsTArray<wr::WrTransformProperty>& aTransformArray);
 
   void SetWindowParameters(LayoutDeviceIntSize size);
   void SetRootDisplayList(gfx::Color aBgColor,
                           Epoch aEpoch,
                           LayerSize aViewportSize,
-                          WrPipelineId pipeline_id,
-                          const WrSize& content_size,
-                          WrBuiltDisplayListDescriptor dl_descriptor,
+                          wr::WrPipelineId pipeline_id,
+                          const wr::LayoutSize& content_size,
+                          wr::BuiltDisplayListDescriptor dl_descriptor,
                           uint8_t *dl_data,
                           size_t dl_size);
 
   void ClearRootDisplayList(Epoch aEpoch,
-                            WrPipelineId pipeline_id);
+                            wr::WrPipelineId pipeline_id);
 
   void SetRootPipeline(wr::PipelineId aPipeline);
 
   void AddImage(wr::ImageKey aKey,
                 const ImageDescriptor& aDescriptor,
                 Range<uint8_t> aBytes);
 
   void AddBlobImage(wr::ImageKey aKey,
@@ -102,218 +102,218 @@ public:
   void SetProfilerEnabled(bool aEnabled);
 
   void RunOnRenderThread(UniquePtr<RendererEvent> aEvent);
   void Readback(gfx::IntSize aSize, uint8_t *aBuffer, uint32_t aBufferSize);
 
   void Pause();
   bool Resume();
 
-  WrIdNamespace GetNamespace();
+  wr::WrIdNamespace GetNamespace();
   GLint GetMaxTextureSize() const { return mMaxTextureSize; }
   bool GetUseANGLE() const { return mUseANGLE; }
 
 protected:
-  WebRenderAPI(WrAPI* aRawApi, wr::WindowId aId, GLint aMaxTextureSize, bool aUseANGLE)
-    : mWrApi(aRawApi)
+  WebRenderAPI(wr::RenderApi* aRawApi, wr::WindowId aId, GLint aMaxTextureSize, bool aUseANGLE)
+    : mRenderApi(aRawApi)
     , mId(aId)
     , mMaxTextureSize(aMaxTextureSize)
     , mUseANGLE(aUseANGLE)
   {}
 
   ~WebRenderAPI();
   // Should be used only for shutdown handling
   void WaitFlushed();
 
-  WrAPI* mWrApi;
+  wr::RenderApi* mRenderApi;
   wr::WindowId mId;
   GLint mMaxTextureSize;
   bool mUseANGLE;
 
   friend class DisplayListBuilder;
   friend class layers::WebRenderBridgeParent;
 };
 
 /// This is a simple C++ wrapper around WrState defined in the rust bindings.
 /// We may want to turn this into a direct wrapper on top of WebRenderFrameBuilder
 /// instead, so the interface may change a bit.
 class DisplayListBuilder {
 public:
   explicit DisplayListBuilder(wr::PipelineId aId,
-                              const WrSize& aContentSize);
+                              const wr::LayoutSize& aContentSize);
   DisplayListBuilder(DisplayListBuilder&&) = default;
 
   ~DisplayListBuilder();
 
   void Begin(const LayerIntSize& aSize);
 
   void End();
-  void Finalize(WrSize& aOutContentSize,
+  void Finalize(wr::LayoutSize& aOutContentSize,
                 wr::BuiltDisplayList& aOutDisplayList);
 
-  void PushStackingContext(const WrRect& aBounds, // TODO: We should work with strongly typed rects
+  void PushStackingContext(const wr::LayoutRect& aBounds, // TODO: We should work with strongly typed rects
                            const uint64_t& aAnimationId,
                            const float* aOpacity,
                            const gfx::Matrix4x4* aTransform,
-                           WrTransformStyle aTransformStyle,
-                           const WrMixBlendMode& aMixBlendMode,
-                           const nsTArray<WrFilterOp>& aFilters);
+                           wr::TransformStyle aTransformStyle,
+                           const wr::MixBlendMode& aMixBlendMode,
+                           const nsTArray<wr::WrFilterOp>& aFilters);
   void PopStackingContext();
 
-  void PushClip(const WrRect& aClipRect,
-                const WrImageMask* aMask);
+  void PushClip(const wr::LayoutRect& aClipRect,
+                const wr::WrImageMask* aMask);
   void PopClip();
 
   void PushBuiltDisplayList(wr::BuiltDisplayList &dl);
 
   void PushScrollLayer(const layers::FrameMetrics::ViewID& aScrollId,
-                       const WrRect& aContentRect, // TODO: We should work with strongly typed rects
-                       const WrRect& aClipRect);
+                       const wr::LayoutRect& aContentRect, // TODO: We should work with strongly typed rects
+                       const wr::LayoutRect& aClipRect);
   void PopScrollLayer();
 
   void PushClipAndScrollInfo(const layers::FrameMetrics::ViewID& aScrollId,
-                             const WrClipId* aClipId);
+                             const wr::WrClipId* aClipId);
   void PopClipAndScrollInfo();
 
-  void PushRect(const WrRect& aBounds,
-                const WrRect& aClip,
-                const WrColor& aColor);
+  void PushRect(const wr::LayoutRect& aBounds,
+                const wr::LayoutRect& aClip,
+                const wr::ColorF& aColor);
 
-  void PushLinearGradient(const WrRect& aBounds,
-                          const WrRect& aClip,
-                          const WrPoint& aStartPoint,
-                          const WrPoint& aEndPoint,
-                          const nsTArray<WrGradientStop>& aStops,
-                          wr::GradientExtendMode aExtendMode,
-                          const WrSize aTileSize,
-                          const WrSize aTileSpacing);
+  void PushLinearGradient(const wr::LayoutRect& aBounds,
+                          const wr::LayoutRect& aClip,
+                          const wr::LayoutPoint& aStartPoint,
+                          const wr::LayoutPoint& aEndPoint,
+                          const nsTArray<wr::GradientStop>& aStops,
+                          wr::ExtendMode aExtendMode,
+                          const wr::LayoutSize aTileSize,
+                          const wr::LayoutSize aTileSpacing);
 
-  void PushRadialGradient(const WrRect& aBounds,
-                          const WrRect& aClip,
-                          const WrPoint& aCenter,
-                          const WrSize& aRadius,
-                          const nsTArray<WrGradientStop>& aStops,
-                          wr::GradientExtendMode aExtendMode,
-                          const WrSize aTileSize,
-                          const WrSize aTileSpacing);
+  void PushRadialGradient(const wr::LayoutRect& aBounds,
+                          const wr::LayoutRect& aClip,
+                          const wr::LayoutPoint& aCenter,
+                          const wr::LayoutSize& aRadius,
+                          const nsTArray<wr::GradientStop>& aStops,
+                          wr::ExtendMode aExtendMode,
+                          const wr::LayoutSize aTileSize,
+                          const wr::LayoutSize aTileSpacing);
 
-  void PushImage(const WrRect& aBounds,
-                 const WrRect& aClip,
+  void PushImage(const wr::LayoutRect& aBounds,
+                 const wr::LayoutRect& aClip,
                  wr::ImageRendering aFilter,
                  wr::ImageKey aImage);
 
-  void PushImage(const WrRect& aBounds,
-                 const WrRect& aClip,
-                 const WrSize& aStretchSize,
-                 const WrSize& aTileSpacing,
+  void PushImage(const wr::LayoutRect& aBounds,
+                 const wr::LayoutRect& aClip,
+                 const wr::LayoutSize& aStretchSize,
+                 const wr::LayoutSize& aTileSpacing,
                  wr::ImageRendering aFilter,
                  wr::ImageKey aImage);
 
-  void PushYCbCrPlanarImage(const WrRect& aBounds,
-                            const WrRect& aClip,
+  void PushYCbCrPlanarImage(const wr::LayoutRect& aBounds,
+                            const wr::LayoutRect& aClip,
                             wr::ImageKey aImageChannel0,
                             wr::ImageKey aImageChannel1,
                             wr::ImageKey aImageChannel2,
-                            WrYuvColorSpace aColorSpace,
+                            wr::WrYuvColorSpace aColorSpace,
                             wr::ImageRendering aFilter);
 
-  void PushNV12Image(const WrRect& aBounds,
-                     const WrRect& aClip,
+  void PushNV12Image(const wr::LayoutRect& aBounds,
+                     const wr::LayoutRect& aClip,
                      wr::ImageKey aImageChannel0,
                      wr::ImageKey aImageChannel1,
-                     WrYuvColorSpace aColorSpace,
+                     wr::WrYuvColorSpace aColorSpace,
                      wr::ImageRendering aFilter);
 
-  void PushYCbCrInterleavedImage(const WrRect& aBounds,
-                                 const WrRect& aClip,
+  void PushYCbCrInterleavedImage(const wr::LayoutRect& aBounds,
+                                 const wr::LayoutRect& aClip,
                                  wr::ImageKey aImageChannel0,
-                                 WrYuvColorSpace aColorSpace,
+                                 wr::WrYuvColorSpace aColorSpace,
                                  wr::ImageRendering aFilter);
 
-  void PushIFrame(const WrRect& aBounds,
+  void PushIFrame(const wr::LayoutRect& aBounds,
                   wr::PipelineId aPipeline);
 
   // XXX WrBorderSides are passed with Range.
   // It is just to bypass compiler bug. See Bug 1357734.
-  void PushBorder(const WrRect& aBounds,
-                  const WrRect& aClip,
-                  const WrBorderWidths& aWidths,
-                  const Range<const WrBorderSide>& aSides,
-                  const WrBorderRadius& aRadius);
+  void PushBorder(const wr::LayoutRect& aBounds,
+                  const wr::LayoutRect& aClip,
+                  const wr::BorderWidths& aWidths,
+                  const Range<const wr::BorderSide>& aSides,
+                  const wr::BorderRadius& aRadius);
 
-  void PushBorderImage(const WrRect& aBounds,
-                       const WrRect& aClip,
-                       const WrBorderWidths& aWidths,
+  void PushBorderImage(const wr::LayoutRect& aBounds,
+                       const wr::LayoutRect& aClip,
+                       const wr::BorderWidths& aWidths,
                        wr::ImageKey aImage,
-                       const WrNinePatchDescriptor& aPatch,
-                       const WrSideOffsets2Df32& aOutset,
-                       const WrRepeatMode& aRepeatHorizontal,
-                       const WrRepeatMode& aRepeatVertical);
+                       const wr::NinePatchDescriptor& aPatch,
+                       const wr::SideOffsets2D_f32& aOutset,
+                       const wr::RepeatMode& aRepeatHorizontal,
+                       const wr::RepeatMode& aRepeatVertical);
 
-  void PushBorderGradient(const WrRect& aBounds,
-                          const WrRect& aClip,
-                          const WrBorderWidths& aWidths,
-                          const WrPoint& aStartPoint,
-                          const WrPoint& aEndPoint,
-                          const nsTArray<WrGradientStop>& aStops,
-                          wr::GradientExtendMode aExtendMode,
-                          const WrSideOffsets2Df32& aOutset);
+  void PushBorderGradient(const wr::LayoutRect& aBounds,
+                          const wr::LayoutRect& aClip,
+                          const wr::BorderWidths& aWidths,
+                          const wr::LayoutPoint& aStartPoint,
+                          const wr::LayoutPoint& aEndPoint,
+                          const nsTArray<wr::GradientStop>& aStops,
+                          wr::ExtendMode aExtendMode,
+                          const wr::SideOffsets2D_f32& aOutset);
 
-  void PushBorderRadialGradient(const WrRect& aBounds,
-                                const WrRect& aClip,
-                                const WrBorderWidths& aWidths,
-                                const WrPoint& aCenter,
-                                const WrSize& aRadius,
-                                const nsTArray<WrGradientStop>& aStops,
-                                wr::GradientExtendMode aExtendMode,
-                                const WrSideOffsets2Df32& aOutset);
+  void PushBorderRadialGradient(const wr::LayoutRect& aBounds,
+                                const wr::LayoutRect& aClip,
+                                const wr::BorderWidths& aWidths,
+                                const wr::LayoutPoint& aCenter,
+                                const wr::LayoutSize& aRadius,
+                                const nsTArray<wr::GradientStop>& aStops,
+                                wr::ExtendMode aExtendMode,
+                                const wr::SideOffsets2D_f32& aOutset);
 
-  void PushText(const WrRect& aBounds,
-                const WrRect& aClip,
+  void PushText(const wr::LayoutRect& aBounds,
+                const wr::LayoutRect& aClip,
                 const gfx::Color& aColor,
                 wr::FontKey aFontKey,
-                Range<const WrGlyphInstance> aGlyphBuffer,
+                Range<const wr::GlyphInstance> aGlyphBuffer,
                 float aGlyphSize);
 
-  void PushBoxShadow(const WrRect& aRect,
-                     const WrRect& aClip,
-                     const WrRect& aBoxBounds,
-                     const WrPoint& aOffset,
-                     const WrColor& aColor,
+  void PushBoxShadow(const wr::LayoutRect& aRect,
+                     const wr::LayoutRect& aClip,
+                     const wr::LayoutRect& aBoxBounds,
+                     const wr::LayoutVector2D& aOffset,
+                     const wr::ColorF& aColor,
                      const float& aBlurRadius,
                      const float& aSpreadRadius,
                      const float& aBorderRadius,
-                     const WrBoxShadowClipMode& aClipMode);
+                     const wr::BoxShadowClipMode& aClipMode);
 
   // Returns the clip id that was most recently pushed with PushClip and that
   // has not yet been popped with PopClip. Return Nothing() if the clip stack
   // is empty.
-  Maybe<WrClipId> TopmostClipId();
+  Maybe<wr::WrClipId> TopmostClipId();
   // Returns the scroll id that was pushed just before the given scroll id. This
   // function returns Nothing() if the given scrollid has not been encountered,
   // or if it is the rootmost scroll id (and therefore has no ancestor).
   Maybe<layers::FrameMetrics::ViewID> ParentScrollIdFor(layers::FrameMetrics::ViewID aScrollId);
 
   // Try to avoid using this when possible.
-  WrState* Raw() { return mWrState; }
+  wr::WrState* Raw() { return mWrState; }
 protected:
-  WrState* mWrState;
+  wr::WrState* mWrState;
 
   // Track the stack of clip ids and scroll layer ids that have been pushed
   // (by PushClip and PushScrollLayer, respectively) and are still active.
   // This is helpful for knowing e.g. what the ancestor scroll id of a particular
   // scroll id is, and doing other "queries" of current state.
-  std::vector<WrClipId> mClipIdStack;
+  std::vector<wr::WrClipId> mClipIdStack;
   std::vector<layers::FrameMetrics::ViewID> mScrollIdStack;
 
   // Track the parent scroll id of each scroll id that we encountered.
   std::unordered_map<layers::FrameMetrics::ViewID, layers::FrameMetrics::ViewID> mScrollParents;
 
   friend class WebRenderAPI;
 };
 
-Maybe<WrImageFormat>
-SurfaceFormatToWrImageFormat(gfx::SurfaceFormat aFormat);
+Maybe<wr::ImageFormat>
+SurfaceFormatToImageFormat(gfx::SurfaceFormat aFormat);
 
 } // namespace wr
 } // namespace mozilla
 
 #endif
--- a/gfx/webrender_bindings/WebRenderTypes.h
+++ b/gfx/webrender_bindings/WebRenderTypes.h
@@ -12,97 +12,92 @@
 #include "mozilla/gfx/Types.h"
 #include "mozilla/gfx/Tools.h"
 #include "mozilla/layers/LayersTypes.h"
 #include "mozilla/Range.h"
 #include "Units.h"
 #include "RoundedRect.h"
 #include "nsStyleConsts.h"
 
-typedef mozilla::Maybe<WrImageMask> MaybeImageMask;
-
 namespace mozilla {
 namespace wr {
 
-typedef WrGradientExtendMode GradientExtendMode;
-typedef WrMixBlendMode MixBlendMode;
-typedef WrImageRendering ImageRendering;
-typedef WrImageFormat ImageFormat;
-typedef WrWindowId WindowId;
-typedef WrPipelineId PipelineId;
-typedef WrImageKey ImageKey;
-typedef WrFontKey FontKey;
-typedef WrEpoch Epoch;
-typedef WrExternalImageId ExternalImageId;
+typedef wr::WrWindowId WindowId;
+typedef wr::WrPipelineId PipelineId;
+typedef wr::WrImageKey ImageKey;
+typedef wr::WrFontKey FontKey;
+typedef wr::WrEpoch Epoch;
+typedef wr::WrExternalImageId ExternalImageId;
 
+typedef mozilla::Maybe<mozilla::wr::WrImageMask> MaybeImageMask;
 typedef Maybe<ExternalImageId> MaybeExternalImageId;
 
 inline WindowId NewWindowId(uint64_t aId) {
   WindowId id;
   id.mHandle = aId;
   return id;
 }
 
 inline Epoch NewEpoch(uint32_t aEpoch) {
   Epoch e;
   e.mHandle = aEpoch;
   return e;
 }
 
-inline Maybe<WrImageFormat>
-SurfaceFormatToWrImageFormat(gfx::SurfaceFormat aFormat) {
+inline Maybe<wr::ImageFormat>
+SurfaceFormatToImageFormat(gfx::SurfaceFormat aFormat) {
   switch (aFormat) {
     case gfx::SurfaceFormat::R8G8B8X8:
       // TODO: use RGBA + opaque flag
-      return Some(WrImageFormat::BGRA8);
+      return Some(wr::ImageFormat::BGRA8);
     case gfx::SurfaceFormat::B8G8R8X8:
       // TODO: WebRender will have a BGRA + opaque flag for this but does not
       // have it yet (cf. issue #732).
     case gfx::SurfaceFormat::B8G8R8A8:
-      return Some(WrImageFormat::BGRA8);
+      return Some(wr::ImageFormat::BGRA8);
     case gfx::SurfaceFormat::B8G8R8:
-      return Some(WrImageFormat::RGB8);
+      return Some(wr::ImageFormat::RGB8);
     case gfx::SurfaceFormat::A8:
-      return Some(WrImageFormat::A8);
+      return Some(wr::ImageFormat::A8);
     case gfx::SurfaceFormat::R8G8:
-      return Some(WrImageFormat::RG8);
+      return Some(wr::ImageFormat::RG8);
     case gfx::SurfaceFormat::UNKNOWN:
-      return Some(WrImageFormat::Invalid);
+      return Some(wr::ImageFormat::Invalid);
     default:
       return Nothing();
   }
 }
 
 inline gfx::SurfaceFormat
-WrImageFormatToSurfaceFormat(ImageFormat aFormat) {
+ImageFormatToSurfaceFormat(ImageFormat aFormat) {
   switch (aFormat) {
     case ImageFormat::BGRA8:
       return gfx::SurfaceFormat::B8G8R8A8;
     case ImageFormat::A8:
       return gfx::SurfaceFormat::A8;
     case ImageFormat::RGB8:
       return gfx::SurfaceFormat::B8G8R8;
     default:
       return gfx::SurfaceFormat::UNKNOWN;
   }
 }
 
-struct ImageDescriptor: public WrImageDescriptor {
+struct ImageDescriptor: public wr::WrImageDescriptor {
   ImageDescriptor(const gfx::IntSize& aSize, gfx::SurfaceFormat aFormat)
   {
-    format = SurfaceFormatToWrImageFormat(aFormat).value();
+    format = wr::SurfaceFormatToImageFormat(aFormat).value();
     width = aSize.width;
     height = aSize.height;
     stride = 0;
     is_opaque = gfx::IsOpaqueFormat(aFormat);
   }
 
   ImageDescriptor(const gfx::IntSize& aSize, uint32_t aByteStride, gfx::SurfaceFormat aFormat)
   {
-    format = SurfaceFormatToWrImageFormat(aFormat).value();
+    format = wr::SurfaceFormatToImageFormat(aFormat).value();
     width = aSize.width;
     height = aSize.height;
     stride = aByteStride;
     is_opaque = gfx::IsOpaqueFormat(aFormat);
   }
 };
 
 // Whenever possible, use wr::WindowId instead of manipulating uint64_t.
@@ -150,17 +145,17 @@ inline PipelineId AsPipelineId(const uin
 }
 
 inline ImageRendering ToImageRendering(gfx::SamplingFilter aFilter)
 {
   return aFilter == gfx::SamplingFilter::POINT ? ImageRendering::Pixelated
                                                : ImageRendering::Auto;
 }
 
-static inline MixBlendMode ToWrMixBlendMode(gfx::CompositionOp compositionOp)
+static inline MixBlendMode ToMixBlendMode(gfx::CompositionOp compositionOp)
 {
   switch (compositionOp)
   {
       case gfx::CompositionOp::OP_MULTIPLY:
         return MixBlendMode::Multiply;
       case gfx::CompositionOp::OP_SCREEN:
         return MixBlendMode::Screen;
       case gfx::CompositionOp::OP_OVERLAY:
@@ -189,316 +184,336 @@ static inline MixBlendMode ToWrMixBlendM
         return MixBlendMode::Color;
       case gfx::CompositionOp::OP_LUMINOSITY:
         return MixBlendMode::Luminosity;
       default:
         return MixBlendMode::Normal;
   }
 }
 
-static inline WrColor ToWrColor(const gfx::Color& color)
+static inline wr::ColorF ToColorF(const gfx::Color& color)
 {
-  WrColor c;
+  wr::ColorF c;
   c.r = color.r;
   c.g = color.g;
   c.b = color.b;
   c.a = color.a;
   return c;
 }
 
 template<class T>
-static inline WrPoint ToWrPoint(const gfx::PointTyped<T>& point)
+static inline wr::LayoutPoint ToLayoutPoint(const gfx::PointTyped<T>& point)
 {
-  WrPoint p;
+  wr::LayoutPoint p;
   p.x = point.x;
   p.y = point.y;
   return p;
 }
 
 template<class T>
-static inline WrPoint ToWrPoint(const gfx::IntPointTyped<T>& point)
+static inline wr::LayoutPoint ToLayoutPoint(const gfx::IntPointTyped<T>& point)
 {
-  return ToWrPoint(IntPointToPoint(point));
+  return ToLayoutPoint(IntPointToPoint(point));
 }
 
-static inline WrPoint ToWrPoint(const gfx::Point& point)
+template<class T>
+static inline wr::LayoutVector2D ToLayoutVector2D(const gfx::PointTyped<T>& point)
 {
-  WrPoint p;
+  wr::LayoutVector2D p;
   p.x = point.x;
   p.y = point.y;
   return p;
 }
 
 template<class T>
-static inline WrRect ToWrRect(const gfx::RectTyped<T>& rect)
+static inline wr::LayoutVector2D ToLayoutVector2D(const gfx::IntPointTyped<T>& point)
 {
-  WrRect r;
-  r.x = rect.x;
-  r.y = rect.y;
-  r.width = rect.width;
-  r.height = rect.height;
+  return ToLayoutVector2D(IntPointToPoint(point));
+}
+
+template<class T>
+static inline wr::LayoutRect ToLayoutRect(const gfx::RectTyped<T>& rect)
+{
+  wr::LayoutRect r;
+  r.origin.x = rect.x;
+  r.origin.y = rect.y;
+  r.size.width = rect.width;
+  r.size.height = rect.height;
   return r;
 }
 
-static inline WrRect ToWrRect(const gfxRect rect)
+static inline wr::LayoutRect ToLayoutRect(const gfxRect rect)
 {
-  WrRect r;
-  r.x = rect.x;
-  r.y = rect.y;
-  r.width = rect.width;
-  r.height = rect.height;
+  wr::LayoutRect r;
+  r.origin.x = rect.x;
+  r.origin.y = rect.y;
+  r.size.width = rect.width;
+  r.size.height = rect.height;
   return r;
 }
 
 template<class T>
-static inline WrRect ToWrRect(const gfx::IntRectTyped<T>& rect)
+static inline wr::LayoutRect ToLayoutRect(const gfx::IntRectTyped<T>& rect)
 {
-  return ToWrRect(IntRectToRect(rect));
+  return ToLayoutRect(IntRectToRect(rect));
 }
 
 template<class T>
-static inline WrSize ToWrSize(const gfx::SizeTyped<T>& size)
+static inline wr::LayoutSize ToLayoutSize(const gfx::SizeTyped<T>& size)
 {
-  WrSize ls;
+  wr::LayoutSize ls;
   ls.width = size.width;
   ls.height = size.height;
   return ls;
 }
 
-static inline WrComplexClipRegion ToWrComplexClipRegion(const RoundedRect& rect)
+static inline wr::WrComplexClipRegion ToWrComplexClipRegion(const RoundedRect& rect)
 {
-  WrComplexClipRegion ret;
-  ret.rect               = ToWrRect(rect.rect);
-  ret.radii.top_left     = ToWrSize(rect.corners.radii[mozilla::eCornerTopLeft]);
-  ret.radii.top_right    = ToWrSize(rect.corners.radii[mozilla::eCornerTopRight]);
-  ret.radii.bottom_left  = ToWrSize(rect.corners.radii[mozilla::eCornerBottomLeft]);
-  ret.radii.bottom_right = ToWrSize(rect.corners.radii[mozilla::eCornerBottomRight]);
+  wr::WrComplexClipRegion ret;
+  ret.rect               = ToLayoutRect(rect.rect);
+  ret.radii.top_left     = ToLayoutSize(rect.corners.radii[mozilla::eCornerTopLeft]);
+  ret.radii.top_right    = ToLayoutSize(rect.corners.radii[mozilla::eCornerTopRight]);
+  ret.radii.bottom_left  = ToLayoutSize(rect.corners.radii[mozilla::eCornerBottomLeft]);
+  ret.radii.bottom_right = ToLayoutSize(rect.corners.radii[mozilla::eCornerBottomRight]);
   return ret;
 }
 
 template<class T>
-static inline WrSize ToWrSize(const gfx::IntSizeTyped<T>& size)
+static inline wr::LayoutSize ToLayoutSize(const gfx::IntSizeTyped<T>& size)
 {
-  return ToWrSize(IntSizeToSize(size));
+  return ToLayoutSize(IntSizeToSize(size));
 }
 
 template<class S, class T>
-static inline WrMatrix ToWrMatrix(const gfx::Matrix4x4Typed<S, T>& m)
+static inline wr::LayoutTransform ToLayoutTransform(const gfx::Matrix4x4Typed<S, T>& m)
 {
-  WrMatrix transform;
-  static_assert(sizeof(m.components) == sizeof(transform.values),
-      "Matrix components size mismatch!");
-  memcpy(transform.values, m.components, sizeof(transform.values));
+  wr::LayoutTransform transform;
+  transform.m11 = m._11;
+  transform.m12 = m._12;
+  transform.m13 = m._13;
+  transform.m14 = m._14;
+  transform.m21 = m._21;
+  transform.m22 = m._22;
+  transform.m23 = m._23;
+  transform.m24 = m._24;
+  transform.m31 = m._31;
+  transform.m32 = m._32;
+  transform.m33 = m._33;
+  transform.m34 = m._34;
+  transform.m41 = m._41;
+  transform.m42 = m._42;
+  transform.m43 = m._43;
+  transform.m44 = m._44;
   return transform;
 }
 
-static inline WrBorderStyle ToWrBorderStyle(const uint8_t& style)
+static inline wr::BorderStyle ToBorderStyle(const uint8_t& style)
 {
   switch (style) {
   case NS_STYLE_BORDER_STYLE_NONE:
-    return WrBorderStyle::None;
+    return wr::BorderStyle::None;
   case NS_STYLE_BORDER_STYLE_SOLID:
-    return WrBorderStyle::Solid;
+    return wr::BorderStyle::Solid;
   case NS_STYLE_BORDER_STYLE_DOUBLE:
-    return WrBorderStyle::Double;
+    return wr::BorderStyle::Double;
   case NS_STYLE_BORDER_STYLE_DOTTED:
-    return WrBorderStyle::Dotted;
+    return wr::BorderStyle::Dotted;
   case NS_STYLE_BORDER_STYLE_DASHED:
-    return WrBorderStyle::Dashed;
+    return wr::BorderStyle::Dashed;
   case NS_STYLE_BORDER_STYLE_HIDDEN:
-    return WrBorderStyle::Hidden;
+    return wr::BorderStyle::Hidden;
   case NS_STYLE_BORDER_STYLE_GROOVE:
-    return WrBorderStyle::Groove;
+    return wr::BorderStyle::Groove;
   case NS_STYLE_BORDER_STYLE_RIDGE:
-    return WrBorderStyle::Ridge;
+    return wr::BorderStyle::Ridge;
   case NS_STYLE_BORDER_STYLE_INSET:
-    return WrBorderStyle::Inset;
+    return wr::BorderStyle::Inset;
   case NS_STYLE_BORDER_STYLE_OUTSET:
-    return WrBorderStyle::Outset;
+    return wr::BorderStyle::Outset;
   default:
     MOZ_ASSERT(false);
   }
-  return WrBorderStyle::None;
+  return wr::BorderStyle::None;
 }
 
-static inline WrBorderSide ToWrBorderSide(const gfx::Color& color, const uint8_t& style)
+static inline wr::BorderSide ToBorderSide(const gfx::Color& color, const uint8_t& style)
 {
-  WrBorderSide bs;
-  bs.color = ToWrColor(color);
-  bs.style = ToWrBorderStyle(style);
+  wr::BorderSide bs;
+  bs.color = ToColorF(color);
+  bs.style = ToBorderStyle(style);
   return bs;
 }
 
-static inline WrBorderRadius ToWrUniformBorderRadius(const LayerSize& aSize)
+static inline wr::BorderRadius ToUniformBorderRadius(const LayerSize& aSize)
 {
-  WrBorderRadius br;
-  br.top_left = ToWrSize(aSize);
-  br.top_right = ToWrSize(aSize);
-  br.bottom_left = ToWrSize(aSize);
-  br.bottom_right = ToWrSize(aSize);
+  wr::BorderRadius br;
+  br.top_left = ToLayoutSize(aSize);
+  br.top_right = ToLayoutSize(aSize);
+  br.bottom_left = ToLayoutSize(aSize);
+  br.bottom_right = ToLayoutSize(aSize);
   return br;
 }
 
-static inline WrBorderRadius ToWrBorderRadius(const LayerSize& topLeft, const LayerSize& topRight,
+static inline wr::BorderRadius ToBorderRadius(const LayerSize& topLeft, const LayerSize& topRight,
                                               const LayerSize& bottomLeft, const LayerSize& bottomRight)
 {
-  WrBorderRadius br;
-  br.top_left = ToWrSize(topLeft);
-  br.top_right = ToWrSize(topRight);
-  br.bottom_left = ToWrSize(bottomLeft);
-  br.bottom_right = ToWrSize(bottomRight);
+  wr::BorderRadius br;
+  br.top_left = ToLayoutSize(topLeft);
+  br.top_right = ToLayoutSize(topRight);
+  br.bottom_left = ToLayoutSize(bottomLeft);
+  br.bottom_right = ToLayoutSize(bottomRight);
   return br;
 }
 
-static inline WrBorderWidths ToWrBorderWidths(float top, float right, float bottom, float left)
+static inline wr::BorderWidths ToBorderWidths(float top, float right, float bottom, float left)
 {
-  WrBorderWidths bw;
+  wr::BorderWidths bw;
   bw.top = top;
   bw.right = right;
   bw.bottom = bottom;
   bw.left = left;
   return bw;
 }
 
-static inline WrNinePatchDescriptor ToWrNinePatchDescriptor(uint32_t width, uint32_t height,
-                                                            const WrSideOffsets2Du32& slice)
+static inline wr::NinePatchDescriptor ToNinePatchDescriptor(uint32_t width, uint32_t height,
+                                                            const wr::SideOffsets2D_u32& slice)
 {
-  WrNinePatchDescriptor patch;
+  NinePatchDescriptor patch;
   patch.width = width;
   patch.height = height;
   patch.slice = slice;
   return patch;
 }
 
-static inline WrSideOffsets2Du32 ToWrSideOffsets2Du32(uint32_t top, uint32_t right, uint32_t bottom, uint32_t left)
+static inline wr::SideOffsets2D_u32 ToSideOffsets2D_u32(uint32_t top, uint32_t right, uint32_t bottom, uint32_t left)
 {
-  WrSideOffsets2Du32 offset;
+  SideOffsets2D_u32 offset;
   offset.top = top;
   offset.right = right;
   offset.bottom = bottom;
   offset.left = left;
   return offset;
 }
 
-static inline WrSideOffsets2Df32 ToWrSideOffsets2Df32(float top, float right, float bottom, float left)
+static inline wr::SideOffsets2D_f32 ToSideOffsets2D_f32(float top, float right, float bottom, float left)
 {
-  WrSideOffsets2Df32 offset;
+  SideOffsets2D_f32 offset;
   offset.top = top;
   offset.right = right;
   offset.bottom = bottom;
   offset.left = left;
   return offset;
 }
 
-static inline WrRepeatMode ToWrRepeatMode(uint8_t repeatMode)
+static inline wr::RepeatMode ToRepeatMode(uint8_t repeatMode)
 {
   switch (repeatMode) {
   case NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH:
-    return WrRepeatMode::Stretch;
+    return wr::RepeatMode::Stretch;
   case NS_STYLE_BORDER_IMAGE_REPEAT_REPEAT:
-    return WrRepeatMode::Repeat;
+    return wr::RepeatMode::Repeat;
   case NS_STYLE_BORDER_IMAGE_REPEAT_ROUND:
-    return WrRepeatMode::Round;
+    return wr::RepeatMode::Round;
   case NS_STYLE_BORDER_IMAGE_REPEAT_SPACE:
-    return WrRepeatMode::Space;
+    return wr::RepeatMode::Space;
   default:
     MOZ_ASSERT(false);
   }
 
-  return WrRepeatMode::Stretch;
+  return wr::RepeatMode::Stretch;
 }
 
 template<class S, class T>
-static inline WrTransformProperty ToWrTransformProperty(uint64_t id,
-                                                        const gfx::Matrix4x4Typed<S, T>& transform)
+static inline wr::WrTransformProperty ToWrTransformProperty(uint64_t id,
+                                                            const gfx::Matrix4x4Typed<S, T>& transform)
 {
-  WrTransformProperty prop;
+  wr::WrTransformProperty prop;
   prop.id = id;
-  prop.transform = ToWrMatrix(transform);
+  prop.transform = ToLayoutTransform(transform);
   return prop;
 }
 
-static inline WrOpacityProperty ToWrOpacityProperty(uint64_t id, const float opacity)
+static inline wr::WrOpacityProperty ToWrOpacityProperty(uint64_t id, const float opacity)
 {
-  WrOpacityProperty prop;
+  wr::WrOpacityProperty prop;
   prop.id = id;
   prop.opacity = opacity;
   return prop;
 }
 
-static inline WrComplexClipRegion ToWrComplexClipRegion(const WrRect& rect,
-                                                        const LayerSize& size)
+static inline wr::WrComplexClipRegion ToWrComplexClipRegion(const wr::LayoutRect& rect,
+                                                            const LayerSize& size)
 {
-  WrComplexClipRegion complex_clip;
+  wr::WrComplexClipRegion complex_clip;
   complex_clip.rect = rect;
-  complex_clip.radii = wr::ToWrUniformBorderRadius(size);
+  complex_clip.radii = wr::ToUniformBorderRadius(size);
   return complex_clip;
 }
 
 template<class T>
-static inline WrComplexClipRegion ToWrComplexClipRegion(const gfx::RectTyped<T>& rect,
-                                                        const LayerSize& size)
+static inline wr::WrComplexClipRegion ToWrComplexClipRegion(const gfx::RectTyped<T>& rect,
+                                                            const LayerSize& size)
 {
-  return ToWrComplexClipRegion(wr::ToWrRect(rect), size);
+  return ToWrComplexClipRegion(wr::ToLayoutRect(rect), size);
 }
 
 // Whenever possible, use wr::ExternalImageId instead of manipulating uint64_t.
 inline uint64_t AsUint64(const ExternalImageId& aId) {
   return static_cast<uint64_t>(aId.mHandle);
 }
 
 static inline ExternalImageId ToExternalImageId(uint64_t aID)
 {
   ExternalImageId Id;
   Id.mHandle = aID;
   return Id;
 }
 
-static inline WrExternalImage RawDataToWrExternalImage(const uint8_t* aBuff,
-                                                       size_t size)
+static inline wr::WrExternalImage RawDataToWrExternalImage(const uint8_t* aBuff,
+                                                           size_t size)
 {
-  return WrExternalImage {
-    WrExternalImageType::RawData,
+  return wr::WrExternalImage {
+    wr::WrExternalImageType::RawData,
     0, 0.0f, 0.0f, 0.0f, 0.0f,
     aBuff, size
   };
 }
 
-static inline WrExternalImage NativeTextureToWrExternalImage(uint32_t aHandle,
-                                                             float u0, float v0,
-                                                             float u1, float v1)
+static inline wr::WrExternalImage NativeTextureToWrExternalImage(uint32_t aHandle,
+                                                                 float u0, float v0,
+                                                                 float u1, float v1)
 {
-  return WrExternalImage {
-    WrExternalImageType::NativeTexture,
+  return wr::WrExternalImage {
+    wr::WrExternalImageType::NativeTexture,
     aHandle, u0, v0, u1, v1,
     nullptr, 0
   };
 }
 
 struct VecU8 {
-  WrVecU8 inner;
+  wr::WrVecU8 inner;
   VecU8() {
     SetEmpty();
   }
   VecU8(VecU8&) = delete;
   VecU8(VecU8&& src) {
     inner = src.inner;
     src.SetEmpty();
   }
 
   VecU8&
   operator=(VecU8&& src) {
     inner = src.inner;
     src.SetEmpty();
     return *this;
   }
 
-  WrVecU8
+  wr::WrVecU8
   Extract() {
-    WrVecU8 ret = inner;
+    wr::WrVecU8 ret = inner;
     SetEmpty();
     return ret;
   }
 
   void
   SetEmpty() {
     inner.data = (uint8_t*)1;
     inner.capacity = 0;
@@ -572,59 +587,59 @@ struct ByteBuffer
           !(memcmp(mData, other.mData, mLength));
   }
 
   size_t mLength;
   uint8_t* mData;
   bool mOwned;
 };
 
-inline WrByteSlice RangeToByteSlice(mozilla::Range<uint8_t> aRange) {
-  return WrByteSlice { aRange.begin().get(), aRange.length() };
+inline wr::ByteSlice RangeToByteSlice(mozilla::Range<uint8_t> aRange) {
+  return wr::ByteSlice { aRange.begin().get(), aRange.length() };
 }
 
-inline mozilla::Range<const uint8_t> ByteSliceToRange(WrByteSlice aWrSlice) {
+inline mozilla::Range<const uint8_t> ByteSliceToRange(wr::ByteSlice aWrSlice) {
   return mozilla::Range<const uint8_t>(aWrSlice.buffer, aWrSlice.len);
 }
 
-inline mozilla::Range<uint8_t> MutByteSliceToRange(MutByteSlice aWrSlice) {
+inline mozilla::Range<uint8_t> MutByteSliceToRange(wr::MutByteSlice aWrSlice) {
   return mozilla::Range<uint8_t>(aWrSlice.buffer, aWrSlice.len);
 }
 
 struct BuiltDisplayList {
-  VecU8 dl;
-  WrBuiltDisplayListDescriptor dl_desc;
+  wr::VecU8 dl;
+  wr::BuiltDisplayListDescriptor dl_desc;
 };
 
-static inline WrFilterOpType ToWrFilterOpType(const layers::CSSFilterType type) {
+static inline wr::WrFilterOpType ToWrFilterOpType(const layers::CSSFilterType type) {
   switch (type) {
     case layers::CSSFilterType::BLUR:
-      return WrFilterOpType::Blur;
+      return wr::WrFilterOpType::Blur;
     case layers::CSSFilterType::BRIGHTNESS:
-      return WrFilterOpType::Brightness;
+      return wr::WrFilterOpType::Brightness;
     case layers::CSSFilterType::CONTRAST:
-      return WrFilterOpType::Contrast;
+      return wr::WrFilterOpType::Contrast;
     case layers::CSSFilterType::GRAYSCALE:
-      return WrFilterOpType::Grayscale;
+      return wr::WrFilterOpType::Grayscale;
     case layers::CSSFilterType::HUE_ROTATE:
-      return WrFilterOpType::HueRotate;
+      return wr::WrFilterOpType::HueRotate;
     case layers::CSSFilterType::INVERT:
-      return WrFilterOpType::Invert;
+      return wr::WrFilterOpType::Invert;
     case layers::CSSFilterType::OPACITY:
-      return WrFilterOpType::Opacity;
+      return wr::WrFilterOpType::Opacity;
     case layers::CSSFilterType::SATURATE:
-      return WrFilterOpType::Saturate;
+      return wr::WrFilterOpType::Saturate;
     case layers::CSSFilterType::SEPIA:
-      return WrFilterOpType::Sepia;
+      return wr::WrFilterOpType::Sepia;
   }
   MOZ_ASSERT_UNREACHABLE("Tried to convert unknown filter type.");
-  return WrFilterOpType::Grayscale;
+  return wr::WrFilterOpType::Grayscale;
 }
 
-static inline WrFilterOp ToWrFilterOp(const layers::CSSFilter& filter) {
+static inline wr::WrFilterOp ToWrFilterOp(const layers::CSSFilter& filter) {
   return {
     ToWrFilterOpType(filter.type),
     filter.argument,
   };
 }
 
 // Corresponds to an "internal" webrender clip id. That is, a
 // ClipId::Clip(x,pipeline_id) maps to a WrClipId{x}. We use a struct wrapper
--- a/gfx/webrender_bindings/cbindgen.toml
+++ b/gfx/webrender_bindings/cbindgen.toml
@@ -7,24 +7,27 @@ autogen_warning = """/* DO NOT MODIFY TH
  *      a. Alternatively, you can clone `https://github.com/rlhunt/cbindgen` and use a tagged release
  *   2. Run `cbindgen toolkit/library/rust/ --crate webrender_bindings -o gfx/webrender_bindings/webrender_ffi_generated.h`
  */"""
 include_version = true
 braces = "SameLine"
 line_length = 100
 tab_width = 2
 language = "C++"
+namespaces = ["mozilla", "wr"]
 
 [parse]
 parse_deps = true
 include = ["webrender", "webrender_api"]
+expand = ["euclid"]
 
 [fn]
 prefix = "WR_INLINE"
 postfix = "WR_FUNC"
 args = "Vertical"
 rename_args = "GeckoCase"
 
 [struct]
 derive_eq = true
+generic_template_specialization = false
 
 [enum]
 add_sentinel = true
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -8,34 +8,21 @@ use gleam::gl;
 
 use webrender_api::*;
 use webrender::renderer::{ReadPixelsFormat, Renderer, RendererOptions};
 use webrender::renderer::{ExternalImage, ExternalImageHandler, ExternalImageSource};
 use webrender::{ApiRecordingReceiver, BinaryRecorder};
 use thread_profiler::register_thread_with_profiler;
 use moz2d_renderer::Moz2dImageRenderer;
 use app_units::Au;
-use euclid::{TypedPoint2D, TypedSize2D, TypedRect, TypedTransform3D, SideOffsets2D};
-use euclid::TypedVector2D;
 use rayon;
+use euclid::SideOffsets2D;
 
 extern crate webrender_api;
 
-type WrAPI = RenderApi;
-type WrBorderStyle = BorderStyle;
-type WrBoxShadowClipMode = BoxShadowClipMode;
-type WrBuiltDisplayListDescriptor = BuiltDisplayListDescriptor;
-type WrImageFormat = ImageFormat;
-type WrImageRendering = ImageRendering;
-type WrMixBlendMode = MixBlendMode;
-type WrTransformStyle = TransformStyle;
-type WrRenderer = Renderer;
-type WrSideOffsets2Du32 = WrSideOffsets2D<u32>;
-type WrSideOffsets2Df32 = WrSideOffsets2D<f32>;
-
 /// cbindgen:field-names=[mNamespace, mHandle]
 type WrExternalImageBufferType = ExternalImageType;
 
 /// cbindgen:field-names=[mHandle]
 /// cbindgen:derive-lt=true
 /// cbindgen:derive-lte=true
 type WrEpoch = Epoch;
 /// cbindgen:field-names=[mHandle]
@@ -47,53 +34,16 @@ type WrIdNamespace = IdNamespace;
 type WrPipelineId = PipelineId;
 /// cbindgen:field-names=[mNamespace, mHandle]
 type WrImageKey = ImageKey;
 /// cbindgen:field-names=[mNamespace, mHandle]
 type WrFontKey = FontKey;
 /// cbindgen:field-names=[mNamespace, mHandle]
 type WrYuvColorSpace = YuvColorSpace;
 
-/// cbindgen:field-names=[mHandle]
-#[repr(C)]
-#[derive(Copy, Clone)]
-pub struct WrExternalImageId(pub u64);
-
-#[repr(u32)]
-#[derive(Copy, Clone)]
-pub enum WrFilterOpType {
-  Blur = 0,
-  Brightness = 1,
-  Contrast = 2,
-  Grayscale = 3,
-  HueRotate = 4,
-  Invert = 5,
-  Opacity = 6,
-  Saturate = 7,
-  Sepia = 8,
-}
-
-#[repr(C)]
-#[derive(Copy, Clone)]
-pub struct WrFilterOp {
-    filter_type: WrFilterOpType,
-    argument: c_float,
-}
-
-impl Into<ExternalImageId> for WrExternalImageId {
-    fn into(self) -> ExternalImageId {
-        ExternalImageId(self.0)
-    }
-}
-impl Into<WrExternalImageId> for ExternalImageId {
-    fn into(self) -> WrExternalImageId {
-        WrExternalImageId(self.0)
-    }
-}
-
 fn make_slice<'a, T>(ptr: *const T, len: usize) -> &'a [T] {
     if ptr.is_null() {
         &[]
     } else {
         unsafe { slice::from_raw_parts(ptr, len) }
     }
 }
 
@@ -101,24 +51,51 @@ fn make_slice_mut<'a, T>(ptr: *mut T, le
     if ptr.is_null() {
         &mut []
     } else {
         unsafe { slice::from_raw_parts_mut(ptr, len) }
     }
 }
 
 #[repr(C)]
-pub struct WrByteSlice {
+pub struct WrVecU8 {
+    data: *mut u8,
+    length: usize,
+    capacity: usize,
+}
+
+impl WrVecU8 {
+    fn to_vec(self) -> Vec<u8> {
+        unsafe { Vec::from_raw_parts(self.data, self.length, self.capacity) }
+    }
+    fn from_vec(mut v: Vec<u8>) -> WrVecU8 {
+        let w = WrVecU8 {
+            data: v.as_mut_ptr(),
+            length: v.len(),
+            capacity: v.capacity(),
+        };
+        mem::forget(v);
+        w
+    }
+}
+
+#[no_mangle]
+pub extern "C" fn wr_vec_u8_free(v: WrVecU8) {
+    v.to_vec();
+}
+
+#[repr(C)]
+pub struct ByteSlice {
     buffer: *const u8,
     len: usize,
 }
 
-impl WrByteSlice {
-    pub fn new(slice: &[u8]) -> WrByteSlice {
-        WrByteSlice {
+impl ByteSlice {
+    pub fn new(slice: &[u8]) -> ByteSlice {
+        ByteSlice {
             buffer: &slice[0],
             len: slice.len(),
         }
     }
 
     pub fn as_slice(&self) -> &[u8] {
         make_slice(self.buffer, self.len)
     }
@@ -139,306 +116,21 @@ impl MutByteSlice {
         }
     }
 
     pub fn as_mut_slice(&mut self) -> &mut [u8] {
         make_slice_mut(self.buffer, self.len)
     }
 }
 
-#[repr(u32)]
-pub enum WrGradientExtendMode {
-    Clamp,
-    Repeat,
-}
-
-impl Into<ExtendMode> for WrGradientExtendMode {
-    fn into(self) -> ExtendMode {
-        match self {
-            WrGradientExtendMode::Clamp => ExtendMode::Clamp,
-            WrGradientExtendMode::Repeat => ExtendMode::Repeat,
-        }
-    }
-}
-
-#[repr(C)]
-#[derive(Debug, Clone, Copy)]
-pub struct WrPoint {
-    x: f32,
-    y: f32,
-}
-
-impl<U> Into<TypedPoint2D<f32, U>> for WrPoint {
-    fn into(self) -> TypedPoint2D<f32, U> {
-        TypedPoint2D::new(self.x, self.y)
-    }
-}
-
-impl<U> Into<TypedVector2D<f32, U>> for WrPoint {
-    fn into(self) -> TypedVector2D<f32, U> {
-        TypedVector2D::new(self.x, self.y)
-    }
-}
-
-#[repr(C)]
-#[derive(Debug, Clone, Copy)]
-pub struct WrSize {
-    width: f32,
-    height: f32,
-}
-
-impl WrSize {
-    fn new(width: f32, height: f32) -> WrSize {
-        WrSize { width: width, height: height }
-    }
-
-    fn zero() -> WrSize {
-        WrSize { width: 0.0, height: 0.0 }
-    }
-}
-
-impl<U> Into<TypedSize2D<f32, U>> for WrSize {
-    fn into(self) -> TypedSize2D<f32, U> {
-        TypedSize2D::new(self.width, self.height)
-    }
-}
-
-#[repr(C)]
-#[derive(Debug, Clone, Copy)]
-pub struct WrRect {
-    x: f32,
-    y: f32,
-    width: f32,
-    height: f32,
-}
-
-impl<U> Into<TypedRect<f32, U>> for WrRect {
-    fn into(self) -> TypedRect<f32, U> {
-        TypedRect::new(TypedPoint2D::new(self.x, self.y),
-                       TypedSize2D::new(self.width, self.height))
-    }
-}
-impl<U> From<TypedRect<f32, U>> for WrRect {
-    fn from(rect: TypedRect<f32, U>) -> Self {
-        WrRect {
-            x: rect.origin.x,
-            y: rect.origin.y,
-            width: rect.size.width,
-            height: rect.size.height,
-        }
-    }
-}
-
-#[repr(C)]
-#[derive(Debug, Clone, Copy)]
-pub struct WrMatrix {
-    values: [f32; 16],
-}
-
-impl<'a, U, E> Into<TypedTransform3D<f32, U, E>> for &'a WrMatrix {
-    fn into(self) -> TypedTransform3D<f32, U, E> {
-        TypedTransform3D::row_major(self.values[0],
-                                    self.values[1],
-                                    self.values[2],
-                                    self.values[3],
-                                    self.values[4],
-                                    self.values[5],
-                                    self.values[6],
-                                    self.values[7],
-                                    self.values[8],
-                                    self.values[9],
-                                    self.values[10],
-                                    self.values[11],
-                                    self.values[12],
-                                    self.values[13],
-                                    self.values[14],
-                                    self.values[15])
-    }
-}
-impl<U, E> Into<TypedTransform3D<f32, U, E>> for WrMatrix {
-    fn into(self) -> TypedTransform3D<f32, U, E> {
-        TypedTransform3D::row_major(self.values[0],
-                                    self.values[1],
-                                    self.values[2],
-                                    self.values[3],
-                                    self.values[4],
-                                    self.values[5],
-                                    self.values[6],
-                                    self.values[7],
-                                    self.values[8],
-                                    self.values[9],
-                                    self.values[10],
-                                    self.values[11],
-                                    self.values[12],
-                                    self.values[13],
-                                    self.values[14],
-                                    self.values[15])
-    }
-}
-
-#[repr(C)]
-#[derive(Debug, Clone, Copy)]
-pub struct WrColor {
-    r: f32,
-    g: f32,
-    b: f32,
-    a: f32,
-}
-
-impl Into<ColorF> for WrColor {
-    fn into(self) -> ColorF {
-        ColorF::new(self.r, self.g, self.b, self.a)
-    }
-}
-
-#[repr(C)]
-#[derive(Debug, Clone, Copy)]
-pub struct WrGlyphInstance {
-    index: u32,
-    point: WrPoint,
-}
-
-impl<'a> Into<GlyphInstance> for &'a WrGlyphInstance {
-    fn into(self) -> GlyphInstance {
-        GlyphInstance {
-            index: self.index,
-            point: self.point.into(),
-        }
-    }
-}
-
-#[repr(C)]
-#[derive(Debug, Clone, Copy)]
-pub struct WrGradientStop {
-    offset: f32,
-    color: WrColor,
-}
-
-impl<'a> Into<GradientStop> for &'a WrGradientStop {
-    fn into(self) -> GradientStop {
-        GradientStop {
-            offset: self.offset,
-            color: self.color.into(),
-        }
-    }
-}
-
-#[repr(C)]
-#[derive(Debug, Clone, Copy)]
-pub struct WrBorderSide {
-    color: WrColor,
-    style: WrBorderStyle,
-}
-
-impl Into<BorderSide> for WrBorderSide {
-    fn into(self) -> BorderSide {
-        BorderSide {
-            color: self.color.into(),
-            style: self.style,
-        }
-    }
-}
-
-#[repr(C)]
-#[derive(Debug, Clone, Copy)]
-pub struct WrBorderRadius {
-    pub top_left: WrSize,
-    pub top_right: WrSize,
-    pub bottom_left: WrSize,
-    pub bottom_right: WrSize,
-}
-
-impl Into<BorderRadius> for WrBorderRadius {
-    fn into(self) -> BorderRadius {
-        BorderRadius {
-            top_left: self.top_left.into(),
-            top_right: self.top_right.into(),
-            bottom_left: self.bottom_left.into(),
-            bottom_right: self.bottom_right.into(),
-        }
-    }
-}
-
-#[repr(C)]
-#[derive(Debug, Clone, Copy)]
-pub struct WrBorderWidths {
-    left: f32,
-    top: f32,
-    right: f32,
-    bottom: f32,
-}
-
-impl Into<BorderWidths> for WrBorderWidths {
-    fn into(self) -> BorderWidths {
-        BorderWidths {
-            left: self.left,
-            top: self.top,
-            right: self.right,
-            bottom: self.bottom,
-        }
-    }
-}
-
-#[repr(C)]
-#[derive(Debug, Clone, Copy)]
-pub struct WrNinePatchDescriptor {
-    width: u32,
-    height: u32,
-    slice: WrSideOffsets2Du32,
-}
-
-impl Into<NinePatchDescriptor> for WrNinePatchDescriptor {
-    fn into(self) -> NinePatchDescriptor {
-        NinePatchDescriptor {
-            width: self.width,
-            height: self.height,
-            slice: self.slice.into(),
-        }
-    }
-}
-
-#[repr(C)]
-#[derive(Debug, Clone, Copy)]
-pub struct WrSideOffsets2D<T> {
-    top: T,
-    right: T,
-    bottom: T,
-    left: T,
-}
-
-impl<T: Copy> Into<SideOffsets2D<T>> for WrSideOffsets2D<T> {
-    fn into(self) -> SideOffsets2D<T> {
-        SideOffsets2D::new(self.top, self.right, self.bottom, self.left)
-    }
-}
-
-#[repr(u32)]
-pub enum WrRepeatMode {
-    Stretch,
-    Repeat,
-    Round,
-    Space,
-}
-
-impl Into<RepeatMode> for WrRepeatMode {
-    fn into(self) -> RepeatMode {
-        match self {
-            WrRepeatMode::Stretch => RepeatMode::Stretch,
-            WrRepeatMode::Repeat => RepeatMode::Repeat,
-            WrRepeatMode::Round => RepeatMode::Round,
-            WrRepeatMode::Space => RepeatMode::Space,
-        }
-    }
-}
-
 #[repr(C)]
 #[derive(Debug, Clone, Copy)]
 pub struct WrImageMask {
     image: WrImageKey,
-    rect: WrRect,
+    rect: LayoutRect,
     repeat: bool,
 }
 
 impl Into<ImageMask> for WrImageMask {
     fn into(self) -> ImageMask {
         ImageMask {
             image: self.image,
             rect: self.rect.into(),
@@ -461,31 +153,58 @@ impl From<ImageMask> for WrImageMask {
             image: image_mask.image,
             rect: image_mask.rect.into(),
             repeat: image_mask.repeat,
         }
     }
 }
 
 #[repr(C)]
-#[derive(Debug, Clone, Copy)]
-pub struct WrComplexClipRegion {
-    rect: WrRect,
-    radii: WrBorderRadius,
+#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+pub struct WrImageDescriptor {
+    pub format: ImageFormat,
+    pub width: u32,
+    pub height: u32,
+    pub stride: u32,
+    pub is_opaque: bool,
 }
 
-impl<'a> Into<ComplexClipRegion> for &'a WrComplexClipRegion {
-    fn into(self) -> ComplexClipRegion {
-        ComplexClipRegion {
-            rect: self.rect.into(),
-            radii: self.radii.into(),
+impl<'a> Into<ImageDescriptor> for &'a WrImageDescriptor {
+    fn into(self) -> ImageDescriptor {
+        ImageDescriptor {
+            width: self.width,
+            height: self.height,
+            stride: if self.stride != 0 {
+                Some(self.stride)
+            } else {
+                None
+            },
+            format: self.format,
+            is_opaque: self.is_opaque,
+            offset: 0,
         }
     }
 }
 
+/// cbindgen:field-names=[mHandle]
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub struct WrExternalImageId(pub u64);
+
+impl Into<ExternalImageId> for WrExternalImageId {
+    fn into(self) -> ExternalImageId {
+        ExternalImageId(self.0)
+    }
+}
+impl Into<WrExternalImageId> for ExternalImageId {
+    fn into(self) -> WrExternalImageId {
+        WrExternalImageId(self.0)
+    }
+}
+
 #[repr(u32)]
 #[allow(dead_code)]
 enum WrExternalImageType {
     NativeTexture,
     RawData,
 }
 
 #[repr(C)]
@@ -546,92 +265,75 @@ impl ExternalImageHandler for WrExternal
 
     fn unlock(&mut self,
               id: ExternalImageId,
               channel_index: u8) {
         (self.unlock_func)(self.external_image_obj, id.into(), channel_index);
     }
 }
 
-/// cbindgen:field-names=[mHandle]
-/// cbindgen:derive-lt=true
-/// cbindgen:derive-lte=true
 #[repr(C)]
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
-pub struct WrWindowId(u64);
-
-#[repr(C)]
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
-pub struct WrImageDescriptor {
-    pub format: WrImageFormat,
-    pub width: u32,
-    pub height: u32,
-    pub stride: u32,
-    pub is_opaque: bool,
+#[derive(Debug, Clone, Copy)]
+pub struct WrComplexClipRegion {
+    rect: LayoutRect,
+    radii: BorderRadius,
 }
 
-impl<'a> Into<ImageDescriptor> for &'a WrImageDescriptor {
-    fn into(self) -> ImageDescriptor {
-        ImageDescriptor {
-            width: self.width,
-            height: self.height,
-            stride: if self.stride != 0 {
-                Some(self.stride)
-            } else {
-                None
-            },
-            format: self.format,
-            is_opaque: self.is_opaque,
-            offset: 0,
+impl<'a> Into<ComplexClipRegion> for &'a WrComplexClipRegion {
+    fn into(self) -> ComplexClipRegion {
+        ComplexClipRegion {
+            rect: self.rect.into(),
+            radii: self.radii.into(),
         }
     }
 }
 
-#[repr(C)]
-pub struct WrVecU8 {
-    data: *mut u8,
-    length: usize,
-    capacity: usize,
+#[repr(u32)]
+#[derive(Copy, Clone)]
+pub enum WrFilterOpType {
+  Blur = 0,
+  Brightness = 1,
+  Contrast = 2,
+  Grayscale = 3,
+  HueRotate = 4,
+  Invert = 5,
+  Opacity = 6,
+  Saturate = 7,
+  Sepia = 8,
 }
 
-impl WrVecU8 {
-    fn to_vec(self) -> Vec<u8> {
-        unsafe { Vec::from_raw_parts(self.data, self.length, self.capacity) }
-    }
-    fn from_vec(mut v: Vec<u8>) -> WrVecU8 {
-        let w = WrVecU8 {
-            data: v.as_mut_ptr(),
-            length: v.len(),
-            capacity: v.capacity(),
-        };
-        mem::forget(v);
-        w
-    }
-}
-
-#[no_mangle]
-pub extern "C" fn wr_vec_u8_free(v: WrVecU8) {
-    v.to_vec();
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub struct WrFilterOp {
+    filter_type: WrFilterOpType,
+    argument: c_float,
 }
 
 /// cbindgen:derive-eq=false
 #[repr(C)]
 #[derive(Debug)]
 pub struct WrTransformProperty {
     pub id: u64,
-    pub transform: WrMatrix,
+    pub transform: LayoutTransform,
 }
 
 #[repr(C)]
 #[derive(Copy, Clone, Debug)]
 pub struct WrOpacityProperty {
     pub id: u64,
     pub opacity: f32,
 }
 
+/// cbindgen:field-names=[mHandle]
+/// cbindgen:derive-lt=true
+/// cbindgen:derive-lte=true
+#[repr(C)]
+#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+pub struct WrWindowId(u64);
+
 fn get_proc_address(glcontext_ptr: *mut c_void,
                     name: &str)
                     -> *const c_void {
 
     extern "C" {
         fn get_proc_address_from_glcontext(glcontext_ptr: *mut c_void,
                                            procname: *const c_char)
                                            -> *const c_void;
@@ -695,89 +397,89 @@ impl webrender_api::RenderNotifier for C
                       event: ExternalEvent) {
         unsafe {
             wr_notifier_external_event(self.window_id, event.unwrap());
         }
     }
 }
 
 #[no_mangle]
-pub extern "C" fn wr_renderer_set_external_image_handler(renderer: &mut WrRenderer,
+pub extern "C" fn wr_renderer_set_external_image_handler(renderer: &mut Renderer,
                                                          external_image_handler: *mut WrExternalImageHandler) {
     if !external_image_handler.is_null() {
         renderer.set_external_image_handler(Box::new(unsafe {
                                                          WrExternalImageHandler {
                                                              external_image_obj:
                                                                  (*external_image_handler).external_image_obj,
                                                              lock_func: (*external_image_handler).lock_func,
                                                              unlock_func: (*external_image_handler).unlock_func,
                                                          }
                                                      }));
     }
 }
 
 #[no_mangle]
-pub extern "C" fn wr_renderer_update(renderer: &mut WrRenderer) {
+pub extern "C" fn wr_renderer_update(renderer: &mut Renderer) {
     renderer.update();
 }
 
 #[no_mangle]
-pub extern "C" fn wr_renderer_render(renderer: &mut WrRenderer,
+pub extern "C" fn wr_renderer_render(renderer: &mut Renderer,
                                      width: u32,
                                      height: u32) {
     renderer.render(DeviceUintSize::new(width, height));
 }
 
 // Call wr_renderer_render() before calling this function.
 #[no_mangle]
-pub unsafe extern "C" fn wr_renderer_readback(renderer: &mut WrRenderer,
+pub unsafe extern "C" fn wr_renderer_readback(renderer: &mut Renderer,
                                               width: u32,
                                               height: u32,
                                               dst_buffer: *mut u8,
                                               buffer_size: usize) {
     assert!(is_in_render_thread());
 
     let mut slice = make_slice_mut(dst_buffer, buffer_size);
     renderer.read_pixels_into(DeviceUintRect::new(
                                 DeviceUintPoint::new(0, 0),
                                 DeviceUintSize::new(width, height)),
                               ReadPixelsFormat::Bgra8,
                               &mut slice);
 }
 
 #[no_mangle]
-pub extern "C" fn wr_renderer_set_profiler_enabled(renderer: &mut WrRenderer,
+pub extern "C" fn wr_renderer_set_profiler_enabled(renderer: &mut Renderer,
                                                    enabled: bool) {
     renderer.set_profiler_enabled(enabled);
 }
 
 #[no_mangle]
-pub extern "C" fn wr_renderer_current_epoch(renderer: &mut WrRenderer,
+pub extern "C" fn wr_renderer_current_epoch(renderer: &mut Renderer,
                                             pipeline_id: WrPipelineId,
                                             out_epoch: &mut WrEpoch)
                                             -> bool {
     if let Some(epoch) = renderer.current_epoch(pipeline_id) {
         *out_epoch = epoch;
         return true;
     }
     return false;
 }
 
 /// cbindgen:postfix=WR_DESTRUCTOR_SAFE_FUNC
 #[no_mangle]
-pub unsafe extern "C" fn wr_renderer_delete(renderer: *mut WrRenderer) {
+pub unsafe extern "C" fn wr_renderer_delete(renderer: *mut Renderer) {
     Box::from_raw(renderer);
 }
 
 pub struct WrRenderedEpochs {
     data: Vec<(WrPipelineId, WrEpoch)>,
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn wr_renderer_flush_rendered_epochs(renderer: &mut WrRenderer) -> *mut WrRenderedEpochs {
+pub unsafe extern "C" fn wr_renderer_flush_rendered_epochs(renderer: &mut Renderer) -> *mut WrRenderedEpochs {
     let map = renderer.flush_rendered_epochs();
     let pipeline_epochs = Box::new(WrRenderedEpochs {
                                        data: map.into_iter().collect(),
                                    });
     return Box::into_raw(pipeline_epochs);
 }
 
 #[no_mangle]
@@ -823,18 +525,18 @@ pub unsafe extern "C" fn wr_thread_pool_
 // Call MakeCurrent before this.
 #[no_mangle]
 pub extern "C" fn wr_window_new(window_id: WrWindowId,
                                 window_width: u32,
                                 window_height: u32,
                                 gl_context: *mut c_void,
                                 thread_pool: *mut WrThreadPool,
                                 enable_profiler: bool,
-                                out_api: &mut *mut WrAPI,
-                                out_renderer: &mut *mut WrRenderer)
+                                out_api: &mut *mut RenderApi,
+                                out_renderer: &mut *mut Renderer)
                                 -> bool {
     assert!(unsafe { is_in_render_thread() });
 
     let recorder: Option<Box<ApiRecordingReceiver>> = if unsafe { gfx_use_wrench() } {
         let name = format!("wr-record-{}.bin", window_id.0);
         Some(Box::new(BinaryRecorder::new(&PathBuf::from(name))))
     } else {
         None
@@ -863,20 +565,20 @@ pub extern "C" fn wr_window_new(window_i
         recorder: recorder,
         blob_image_renderer: Some(Box::new(Moz2dImageRenderer::new(workers.clone()))),
         workers: Some(workers.clone()),
         cache_expiry_frames: 60, // see https://github.com/servo/webrender/pull/1294#issuecomment-304318800
         ..Default::default()
     };
 
     let window_size = DeviceUintSize::new(window_width, window_height);
-    let (renderer, sender) = match WrRenderer::new(gl, opts, window_size) {
+    let (renderer, sender) = match Renderer::new(gl, opts, window_size) {
         Ok((renderer, sender)) => (renderer, sender),
         Err(e) => {
-            println!(" Failed to create a WrRenderer: {:?}", e);
+            println!(" Failed to create a Renderer: {:?}", e);
             let msg = CString::new(format!("wr_window_new: {:?}", e)).unwrap();
             unsafe {
                 gfx_critical_note(msg.as_ptr());
             }
             return false;
         },
     };
 
@@ -887,49 +589,49 @@ pub extern "C" fn wr_window_new(window_i
     *out_api = Box::into_raw(Box::new(sender.create_api()));
     *out_renderer = Box::into_raw(Box::new(renderer));
 
     return true;
 }
 
 /// cbindgen:postfix=WR_DESTRUCTOR_SAFE_FUNC
 #[no_mangle]
-pub unsafe extern "C" fn wr_api_delete(api: *mut WrAPI) {
+pub unsafe extern "C" fn wr_api_delete(api: *mut RenderApi) {
     let api = Box::from_raw(api);
     api.shut_down();
 }
 
 #[no_mangle]
-pub extern "C" fn wr_api_add_image(api: &mut WrAPI,
+pub extern "C" fn wr_api_add_image(api: &mut RenderApi,
                                    image_key: WrImageKey,
                                    descriptor: &WrImageDescriptor,
-                                   bytes: WrByteSlice) {
+                                   bytes: ByteSlice) {
     assert!(unsafe { is_in_compositor_thread() });
     let copied_bytes = bytes.as_slice().to_owned();
     api.add_image(image_key,
                   descriptor.into(),
                   ImageData::new(copied_bytes),
                   None);
 }
 
 #[no_mangle]
-pub extern "C" fn wr_api_add_blob_image(api: &mut WrAPI,
+pub extern "C" fn wr_api_add_blob_image(api: &mut RenderApi,
                                         image_key: WrImageKey,
                                         descriptor: &WrImageDescriptor,
-                                        bytes: WrByteSlice) {
+                                        bytes: ByteSlice) {
     assert!(unsafe { is_in_compositor_thread() });
     let copied_bytes = bytes.as_slice().to_owned();
     api.add_image(image_key,
                   descriptor.into(),
                   ImageData::new_blob_image(copied_bytes),
                   None);
 }
 
 #[no_mangle]
-pub extern "C" fn wr_api_add_external_image(api: &mut WrAPI,
+pub extern "C" fn wr_api_add_external_image(api: &mut RenderApi,
                                             image_key: WrImageKey,
                                             descriptor: &WrImageDescriptor,
                                             external_image_id: WrExternalImageId,
                                             buffer_type: WrExternalImageBufferType,
                                             channel_index: u8) {
     assert!(unsafe { is_in_compositor_thread() });
     api.add_image(image_key,
                   descriptor.into(),
@@ -937,73 +639,73 @@ pub extern "C" fn wr_api_add_external_im
                                           id: external_image_id.into(),
                                           channel_index: channel_index,
                                           image_type: buffer_type,
                                       }),
                   None);
 }
 
 #[no_mangle]
-pub extern "C" fn wr_api_add_external_image_buffer(api: &mut WrAPI,
+pub extern "C" fn wr_api_add_external_image_buffer(api: &mut RenderApi,
                                                    image_key: WrImageKey,
                                                    descriptor: &WrImageDescriptor,
                                                    external_image_id: WrExternalImageId) {
     assert!(unsafe { is_in_compositor_thread() });
     api.add_image(image_key,
                   descriptor.into(),
                   ImageData::External(ExternalImageData {
                                           id: external_image_id.into(),
                                           channel_index: 0,
                                           image_type: ExternalImageType::ExternalBuffer,
                                       }),
                   None);
 }
 
 #[no_mangle]
-pub extern "C" fn wr_api_update_image(api: &mut WrAPI,
+pub extern "C" fn wr_api_update_image(api: &mut RenderApi,
                                       key: WrImageKey,
                                       descriptor: &WrImageDescriptor,
-                                      bytes: WrByteSlice) {
+                                      bytes: ByteSlice) {
     assert!(unsafe { is_in_compositor_thread() });
     let copied_bytes = bytes.as_slice().to_owned();
 
     api.update_image(key, descriptor.into(), ImageData::new(copied_bytes), None);
 }
 
 #[no_mangle]
-pub extern "C" fn wr_api_delete_image(api: &mut WrAPI,
+pub extern "C" fn wr_api_delete_image(api: &mut RenderApi,
                                       key: WrImageKey) {
     assert!(unsafe { is_in_compositor_thread() });
     api.delete_image(key)
 }
 
 #[no_mangle]
-pub extern "C" fn wr_api_set_root_pipeline(api: &mut WrAPI,
+pub extern "C" fn wr_api_set_root_pipeline(api: &mut RenderApi,
                                            pipeline_id: WrPipelineId) {
     api.set_root_pipeline(pipeline_id);
     api.generate_frame(None);
 }
 
 #[no_mangle]
-pub extern "C" fn wr_api_set_window_parameters(api: &mut WrAPI,
+pub extern "C" fn wr_api_set_window_parameters(api: &mut RenderApi,
                                                width: i32,
                                                height: i32) {
     let size = DeviceUintSize::new(width as u32, height as u32);
     api.set_window_parameters(size, DeviceUintRect::new(DeviceUintPoint::new(0, 0), size));
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn wr_api_set_root_display_list(api: &mut WrAPI,
-                                                      color: WrColor,
+pub unsafe extern "C" fn wr_api_set_root_display_list(api: &mut RenderApi,
+                                                      color: ColorF,
                                                       epoch: WrEpoch,
                                                       viewport_width: f32,
                                                       viewport_height: f32,
                                                       pipeline_id: WrPipelineId,
-                                                      content_size: WrSize,
-                                                      dl_descriptor: WrBuiltDisplayListDescriptor,
+                                                      content_size: LayoutSize,
+                                                      dl_descriptor: BuiltDisplayListDescriptor,
                                                       dl_data: *mut u8,
                                                       dl_size: usize) {
     let color = if color.a == 0.0 {
         None
     } else {
         Some(color.into())
     };
     // See the documentation of set_display_list in api.rs. I don't think
@@ -1020,36 +722,36 @@ pub unsafe extern "C" fn wr_api_set_root
     api.set_display_list(color,
                          epoch,
                          LayoutSize::new(viewport_width, viewport_height),
                          (pipeline_id, content_size.into(), dl),
                          preserve_frame_state);
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn wr_api_clear_root_display_list(api: &mut WrAPI,
+pub unsafe extern "C" fn wr_api_clear_root_display_list(api: &mut RenderApi,
                                                         epoch: WrEpoch,
                                                         pipeline_id: WrPipelineId) {
     let preserve_frame_state = true;
-    let frame_builder = WebRenderFrameBuilder::new(pipeline_id, WrSize::zero());
+    let frame_builder = WebRenderFrameBuilder::new(pipeline_id, LayoutSize::zero());
 
     api.set_display_list(None,
                          epoch,
                          LayoutSize::new(0.0, 0.0),
                          frame_builder.dl_builder.finalize(),
                          preserve_frame_state);
 }
 
 #[no_mangle]
-pub extern "C" fn wr_api_generate_frame(api: &mut WrAPI) {
+pub extern "C" fn wr_api_generate_frame(api: &mut RenderApi) {
     api.generate_frame(None);
 }
 
 #[no_mangle]
-pub extern "C" fn wr_api_generate_frame_with_properties(api: &mut WrAPI,
+pub extern "C" fn wr_api_generate_frame_with_properties(api: &mut RenderApi,
                                                         opacity_array: *const WrOpacityProperty,
                                                         opacity_count: usize,
                                                         transform_array: *const WrTransformProperty,
                                                         transform_count: usize) {
     let mut properties = DynamicProperties {
         transforms: Vec::new(),
         floats: Vec::new(),
     };
@@ -1079,47 +781,47 @@ pub extern "C" fn wr_api_generate_frame_
         }
     }
 
     api.generate_frame(Some(properties));
 }
 
 /// cbindgen:postfix=WR_DESTRUCTOR_SAFE_FUNC
 #[no_mangle]
-pub extern "C" fn wr_api_send_external_event(api: &mut WrAPI,
+pub extern "C" fn wr_api_send_external_event(api: &mut RenderApi,
                                              evt: usize) {
     assert!(unsafe { !is_in_render_thread() });
 
     api.send_external_event(ExternalEvent::from_raw(evt));
 }
 
 #[no_mangle]
-pub extern "C" fn wr_api_add_raw_font(api: &mut WrAPI,
+pub extern "C" fn wr_api_add_raw_font(api: &mut RenderApi,
                                       key: WrFontKey,
                                       font_buffer: *mut u8,
                                       buffer_size: usize,
                                       index: u32) {
     assert!(unsafe { is_in_compositor_thread() });
 
     let font_slice = make_slice(font_buffer, buffer_size);
     let mut font_vector = Vec::new();
     font_vector.extend_from_slice(font_slice);
 
     api.add_raw_font(key, font_vector, index);
 }
 
 #[no_mangle]
-pub extern "C" fn wr_api_delete_font(api: &mut WrAPI,
+pub extern "C" fn wr_api_delete_font(api: &mut RenderApi,
                                      key: WrFontKey) {
     assert!(unsafe { is_in_compositor_thread() });
     api.delete_font(key);
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn wr_api_get_namespace(api: &mut WrAPI) -> WrIdNamespace {
+pub unsafe extern "C" fn wr_api_get_namespace(api: &mut RenderApi) -> WrIdNamespace {
     api.id_namespace
 }
 
 // RenderThread WIP notes:
 // In order to separate the compositor thread (or ipc receiver) and the render
 // thread, some of the logic below needs to be rewritten. In particular
 // the WrWindowState and Notifier implementations aren't designed to work with
 // a separate render thread.
@@ -1132,33 +834,33 @@ pub unsafe extern "C" fn wr_api_get_name
 pub struct WebRenderFrameBuilder {
     pub root_pipeline_id: WrPipelineId,
     pub dl_builder: webrender_api::DisplayListBuilder,
     pub scroll_clips_defined: HashSet<ClipId>,
 }
 
 impl WebRenderFrameBuilder {
     pub fn new(root_pipeline_id: WrPipelineId,
-               content_size: WrSize) -> WebRenderFrameBuilder {
+               content_size: LayoutSize) -> WebRenderFrameBuilder {
         WebRenderFrameBuilder {
             root_pipeline_id: root_pipeline_id,
             dl_builder: webrender_api::DisplayListBuilder::new(root_pipeline_id, content_size.into()),
             scroll_clips_defined: HashSet::new(),
         }
     }
 }
 
 pub struct WrState {
     pipeline_id: WrPipelineId,
     frame_builder: WebRenderFrameBuilder,
 }
 
 #[no_mangle]
 pub extern "C" fn wr_state_new(pipeline_id: WrPipelineId,
-                               content_size: WrSize) -> *mut WrState {
+                               content_size: LayoutSize) -> *mut WrState {
     assert!(unsafe { !is_in_render_thread() });
 
     let state = Box::new(WrState {
                              pipeline_id: pipeline_id,
                              frame_builder: WebRenderFrameBuilder::new(pipeline_id,
                                                                        content_size),
                          });
 
@@ -1199,22 +901,22 @@ pub extern "C" fn wr_dp_begin(state: &mu
 #[no_mangle]
 pub extern "C" fn wr_dp_end(state: &mut WrState) {
     assert!(unsafe { !is_in_render_thread() });
     state.frame_builder.dl_builder.pop_stacking_context();
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_stacking_context(state: &mut WrState,
-                                              bounds: WrRect,
+                                              bounds: LayoutRect,
                                               animation_id: u64,
                                               opacity: *const f32,
-                                              transform: *const WrMatrix,
-                                              transform_style: WrTransformStyle,
-                                              mix_blend_mode: WrMixBlendMode,
+                                              transform: *const LayoutTransform,
+                                              transform_style: TransformStyle,
+                                              mix_blend_mode: MixBlendMode,
                                               filters: *const WrFilterOp,
                                               filter_count: usize) {
     assert!(unsafe { !is_in_render_thread() });
 
     let bounds = bounds.into();
 
     let c_filters = make_slice(filters, filter_count);
     let mut filters : Vec<FilterOp> = c_filters.iter().map(|c_filter| {
@@ -1238,17 +940,17 @@ pub extern "C" fn wr_dp_push_stacking_co
         }
     } else {
         filters.push(FilterOp::Opacity(PropertyBinding::Binding(PropertyBindingKey::new(animation_id))));
     }
 
     let transform = unsafe { transform.as_ref() };
     let transform_binding = match animation_id {
         0 => match transform {
-            Some(transform) => Some(PropertyBinding::Value(transform.into())),
+            Some(transform) => Some(PropertyBinding::Value(transform.clone())),
             None => None,
         },
         _ => Some(PropertyBinding::Binding(PropertyBindingKey::new(animation_id))),
     };
 
     state.frame_builder
          .dl_builder
          .push_stacking_context(webrender_api::ScrollPolicy::Scrollable,
@@ -1263,17 +965,17 @@ pub extern "C" fn wr_dp_push_stacking_co
 #[no_mangle]
 pub extern "C" fn wr_dp_pop_stacking_context(state: &mut WrState) {
     assert!(unsafe { !is_in_render_thread() });
     state.frame_builder.dl_builder.pop_stacking_context();
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_clip(state: &mut WrState,
-                                  rect: WrRect,
+                                  rect: LayoutRect,
                                   complex: *const WrComplexClipRegion,
                                   complex_count: usize,
                                   mask: *const WrImageMask)
                                   -> u64 {
     assert!(unsafe { is_in_main_thread() });
     let clip_rect: LayoutRect = rect.into();
     let complex_slice = make_slice(complex, complex_count);
     let complex_iter = complex_slice.iter().map(|x| x.into());
@@ -1296,18 +998,18 @@ pub extern "C" fn wr_dp_push_clip(state:
 pub extern "C" fn wr_dp_pop_clip(state: &mut WrState) {
     assert!(unsafe { !is_in_render_thread() });
     state.frame_builder.dl_builder.pop_clip_id();
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_scroll_layer(state: &mut WrState,
                                           scroll_id: u64,
-                                          content_rect: WrRect,
-                                          clip_rect: WrRect) {
+                                          content_rect: LayoutRect,
+                                          clip_rect: LayoutRect) {
     assert!(unsafe { is_in_main_thread() });
     let clip_id = ClipId::new(scroll_id, state.pipeline_id);
     // Avoid defining multiple scroll clips with the same clip id, as that
     // results in undefined behaviour or assertion failures.
     if !state.frame_builder.scroll_clips_defined.contains(&clip_id) {
         let content_rect: LayoutRect = content_rect.into();
         let clip_rect: LayoutRect = clip_rect.into();
 
@@ -1319,20 +1021,20 @@ pub extern "C" fn wr_dp_push_scroll_laye
 
 #[no_mangle]
 pub extern "C" fn wr_dp_pop_scroll_layer(state: &mut WrState) {
     assert!(unsafe { is_in_main_thread() });
     state.frame_builder.dl_builder.pop_clip_id();
 }
 
 #[no_mangle]
-pub extern "C" fn wr_scroll_layer_with_id(api: &mut WrAPI,
+pub extern "C" fn wr_scroll_layer_with_id(api: &mut RenderApi,
                                           pipeline_id: WrPipelineId,
                                           scroll_id: u64,
-                                          new_scroll_origin: WrPoint) {
+                                          new_scroll_origin: LayoutPoint) {
     assert!(unsafe { is_in_compositor_thread() });
     let clip_id = ClipId::new(scroll_id, pipeline_id);
     api.scroll_node_with_id(new_scroll_origin.into(), clip_id, ScrollClamping::NoClamping);
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_clip_and_scroll_info(state: &mut WrState,
                                                   scroll_id: u64,
@@ -1352,153 +1054,152 @@ pub extern "C" fn wr_dp_push_clip_and_sc
 #[no_mangle]
 pub extern "C" fn wr_dp_pop_clip_and_scroll_info(state: &mut WrState) {
     assert!(unsafe { is_in_main_thread() });
     state.frame_builder.dl_builder.pop_clip_id();
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_iframe(state: &mut WrState,
-                                    rect: WrRect,
+                                    rect: LayoutRect,
                                     pipeline_id: WrPipelineId) {
     assert!(unsafe { is_in_main_thread() });
 
     state.frame_builder.dl_builder.push_iframe(rect.into(), None, pipeline_id);
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_rect(state: &mut WrState,
-                                  rect: WrRect,
-                                  clip: WrRect,
-                                  color: WrColor) {
+                                  rect: LayoutRect,
+                                  clip: LayoutRect,
+                                  color: ColorF) {
     assert!(unsafe { !is_in_render_thread() });
 
     state.frame_builder.dl_builder.push_rect(rect.into(),
                                              Some(LocalClip::Rect(clip.into())),
                                              color.into());
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_image(state: &mut WrState,
-                                   bounds: WrRect,
-                                   clip: WrRect,
-                                   stretch_size: WrSize,
-                                   tile_spacing: WrSize,
-                                   image_rendering: WrImageRendering,
+                                   bounds: LayoutRect,
+                                   clip: LayoutRect,
+                                   stretch_size: LayoutSize,
+                                   tile_spacing: LayoutSize,
+                                   image_rendering: ImageRendering,
                                    key: WrImageKey) {
     assert!(unsafe { is_in_main_thread() || is_in_compositor_thread() });
 
     state.frame_builder
          .dl_builder
          .push_image(bounds.into(),
                      Some(LocalClip::Rect(clip.into())),
                      stretch_size.into(),
                      tile_spacing.into(),
                      image_rendering,
                      key);
 }
 
 /// Push a 3 planar yuv image.
 #[no_mangle]
 pub extern "C" fn wr_dp_push_yuv_planar_image(state: &mut WrState,
-                                              bounds: WrRect,
-                                              clip: WrRect,
+                                              bounds: LayoutRect,
+                                              clip: LayoutRect,
                                               image_key_0: WrImageKey,
                                               image_key_1: WrImageKey,
                                               image_key_2: WrImageKey,
                                               color_space: WrYuvColorSpace,
-                                              image_rendering: WrImageRendering) {
+                                              image_rendering: ImageRendering) {
     assert!(unsafe { is_in_main_thread() || is_in_compositor_thread() });
 
     state.frame_builder
          .dl_builder
          .push_yuv_image(bounds.into(),
                          Some(LocalClip::Rect(clip.into())),
                          YuvData::PlanarYCbCr(image_key_0, image_key_1, image_key_2),
                          color_space,
                          image_rendering);
 }
 
 /// Push a 2 planar NV12 image.
 #[no_mangle]
 pub extern "C" fn wr_dp_push_yuv_NV12_image(state: &mut WrState,
-                                            bounds: WrRect,
-                                            clip: WrRect,
+                                            bounds: LayoutRect,
+                                            clip: LayoutRect,
                                             image_key_0: WrImageKey,
                                             image_key_1: WrImageKey,
                                             color_space: WrYuvColorSpace,
-                                            image_rendering: WrImageRendering) {
+                                            image_rendering: ImageRendering) {
     assert!(unsafe { is_in_main_thread() || is_in_compositor_thread() });
 
     state.frame_builder
          .dl_builder
          .push_yuv_image(bounds.into(),
                          Some(LocalClip::Rect(clip.into())),
                          YuvData::NV12(image_key_0, image_key_1),
                          color_space,
                          image_rendering);
 }
 
 /// Push a yuv interleaved image.
 #[no_mangle]
 pub extern "C" fn wr_dp_push_yuv_interleaved_image(state: &mut WrState,
-                                                   bounds: WrRect,
-                                                   clip: WrRect,
+                                                   bounds: LayoutRect,
+                                                   clip: LayoutRect,
                                                    image_key_0: WrImageKey,
                                                    color_space: WrYuvColorSpace,
-                                                   image_rendering: WrImageRendering) {
+                                                   image_rendering: ImageRendering) {
     assert!(unsafe { is_in_main_thread() || is_in_compositor_thread() });
 
     state.frame_builder
          .dl_builder
          .push_yuv_image(bounds.into(),
                          Some(LocalClip::Rect(clip.into())),
                          YuvData::InterleavedYCbCr(image_key_0),
                          color_space,
                          image_rendering);
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_text(state: &mut WrState,
-                                  bounds: WrRect,
-                                  clip: WrRect,
-                                  color: WrColor,
+                                  bounds: LayoutRect,
+                                  clip: LayoutRect,
+                                  color: ColorF,
                                   font_key: WrFontKey,
-                                  glyphs: *const WrGlyphInstance,
+                                  glyphs: *const GlyphInstance,
                                   glyph_count: u32,
                                   glyph_size: f32) {
     assert!(unsafe { is_in_main_thread() });
 
     let glyph_slice = make_slice(glyphs, glyph_count as usize);
-    let glyph_vector: Vec<_> = glyph_slice.iter().map(|x| x.into()).collect();
 
     let colorf = ColorF::new(color.r, color.g, color.b, color.a);
 
     let glyph_options = None; // TODO
     state.frame_builder
          .dl_builder
          .push_text(bounds.into(),
                     Some(LocalClip::Rect(clip.into())),
-                    &glyph_vector,
+                    &glyph_slice,
                     font_key,
                     colorf,
                     Au::from_f32_px(glyph_size),
                     glyph_options);
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_border(state: &mut WrState,
-                                    rect: WrRect,
-                                    clip: WrRect,
-                                    widths: WrBorderWidths,
-                                    top: WrBorderSide,
-                                    right: WrBorderSide,
-                                    bottom: WrBorderSide,
-                                    left: WrBorderSide,
-                                    radius: WrBorderRadius) {
+                                    rect: LayoutRect,
+                                    clip: LayoutRect,
+                                    widths: BorderWidths,
+                                    top: BorderSide,
+                                    right: BorderSide,
+                                    bottom: BorderSide,
+                                    left: BorderSide,
+                                    radius: BorderRadius) {
     assert!(unsafe { is_in_main_thread() });
 
     let border_details = BorderDetails::Normal(NormalBorder {
                                                    left: left.into(),
                                                    right: right.into(),
                                                    top: top.into(),
                                                    bottom: bottom.into(),
                                                    radius: radius.into(),
@@ -1508,24 +1209,24 @@ pub extern "C" fn wr_dp_push_border(stat
          .push_border(rect.into(),
                       Some(LocalClip::Rect(clip.into())),
                       widths.into(),
                       border_details);
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_border_image(state: &mut WrState,
-                                          rect: WrRect,
-                                          clip: WrRect,
-                                          widths: WrBorderWidths,
+                                          rect: LayoutRect,
+                                          clip: LayoutRect,
+                                          widths: BorderWidths,
                                           image: WrImageKey,
-                                          patch: WrNinePatchDescriptor,
-                                          outset: WrSideOffsets2Df32,
-                                          repeat_horizontal: WrRepeatMode,
-                                          repeat_vertical: WrRepeatMode) {
+                                          patch: NinePatchDescriptor,
+                                          outset: SideOffsets2D<f32>,
+                                          repeat_horizontal: RepeatMode,
+                                          repeat_vertical: RepeatMode) {
     assert!(unsafe { is_in_main_thread() });
     let border_details =
         BorderDetails::Image(ImageBorder {
                                  image_key: image,
                                  patch: patch.into(),
                                  fill: false,
                                  outset: outset.into(),
                                  repeat_horizontal: repeat_horizontal.into(),
@@ -1536,29 +1237,29 @@ pub extern "C" fn wr_dp_push_border_imag
          .push_border(rect.into(),
                       Some(LocalClip::Rect(clip.into())),
                       widths.into(),
                       border_details);
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_border_gradient(state: &mut WrState,
-                                             rect: WrRect,
-                                             clip: WrRect,
-                                             widths: WrBorderWidths,
-                                             start_point: WrPoint,
-                                             end_point: WrPoint,
-                                             stops: *const WrGradientStop,
+                                             rect: LayoutRect,
+                                             clip: LayoutRect,
+                                             widths: BorderWidths,
+                                             start_point: LayoutPoint,
+                                             end_point: LayoutPoint,
+                                             stops: *const GradientStop,
                                              stops_count: usize,
-                                             extend_mode: WrGradientExtendMode,
-                                             outset: WrSideOffsets2Df32) {
+                                             extend_mode: ExtendMode,
+                                             outset: SideOffsets2D<f32>) {
     assert!(unsafe { is_in_main_thread() });
 
     let stops_slice = make_slice(stops, stops_count);
-    let stops_vector = stops_slice.iter().map(|x| x.into()).collect();
+    let stops_vector = stops_slice.to_owned();
 
     let border_details = BorderDetails::Gradient(GradientBorder {
                                                      gradient:
                                                          state.frame_builder
                                                               .dl_builder
                                                               .create_gradient(start_point.into(),
                                                                                end_point.into(),
                                                                                stops_vector,
@@ -1570,29 +1271,29 @@ pub extern "C" fn wr_dp_push_border_grad
          .push_border(rect.into(),
                       Some(LocalClip::Rect(clip.into())),
                       widths.into(),
                       border_details);
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_border_radial_gradient(state: &mut WrState,
-                                                    rect: WrRect,
-                                                    clip: WrRect,
-                                                    widths: WrBorderWidths,
-                                                    center: WrPoint,
-                                                    radius: WrSize,
-                                                    stops: *const WrGradientStop,
+                                                    rect: LayoutRect,
+                                                    clip: LayoutRect,
+                                                    widths: BorderWidths,
+                                                    center: LayoutPoint,
+                                                    radius: LayoutSize,
+                                                    stops: *const GradientStop,
                                                     stops_count: usize,
-                                                    extend_mode: WrGradientExtendMode,
-                                                    outset: WrSideOffsets2Df32) {
+                                                    extend_mode: ExtendMode,
+                                                    outset: SideOffsets2D<f32>) {
     assert!(unsafe { is_in_main_thread() });
 
     let stops_slice = make_slice(stops, stops_count);
-    let stops_vector = stops_slice.iter().map(|x| x.into()).collect();
+    let stops_vector = stops_slice.to_owned();
 
     let border_details =
         BorderDetails::RadialGradient(RadialGradientBorder {
                                           gradient:
                                               state.frame_builder
                                                    .dl_builder
                                                    .create_radial_gradient(center.into(),
                                                                            radius.into(),
@@ -1605,29 +1306,29 @@ pub extern "C" fn wr_dp_push_border_radi
          .push_border(rect.into(),
                       Some(LocalClip::Rect(clip.into())),
                       widths.into(),
                       border_details);
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_linear_gradient(state: &mut WrState,
-                                             rect: WrRect,
-                                             clip: WrRect,
-                                             start_point: WrPoint,
-                                             end_point: WrPoint,
-                                             stops: *const WrGradientStop,
+                                             rect: LayoutRect,
+                                             clip: LayoutRect,
+                                             start_point: LayoutPoint,
+                                             end_point: LayoutPoint,
+                                             stops: *const GradientStop,
                                              stops_count: usize,
-                                             extend_mode: WrGradientExtendMode,
-                                             tile_size: WrSize,
-                                             tile_spacing: WrSize) {
+                                             extend_mode: ExtendMode,
+                                             tile_size: LayoutSize,
+                                             tile_spacing: LayoutSize) {
     assert!(unsafe { is_in_main_thread() });
 
     let stops_slice = make_slice(stops, stops_count);
-    let stops_vector = stops_slice.iter().map(|x| x.into()).collect();
+    let stops_vector = stops_slice.to_owned();
 
     let gradient = state.frame_builder
                         .dl_builder
                         .create_gradient(start_point.into(),
                                          end_point.into(),
                                          stops_vector,
                                          extend_mode.into());
     state.frame_builder
@@ -1636,29 +1337,29 @@ pub extern "C" fn wr_dp_push_linear_grad
                         Some(LocalClip::Rect(clip.into())),
                         gradient,
                         tile_size.into(),
                         tile_spacing.into());
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_radial_gradient(state: &mut WrState,
-                                             rect: WrRect,
-                                             clip: WrRect,
-                                             center: WrPoint,
-                                             radius: WrSize,
-                                             stops: *const WrGradientStop,
+                                             rect: LayoutRect,
+                                             clip: LayoutRect,
+                                             center: LayoutPoint,
+                                             radius: LayoutSize,
+                                             stops: *const GradientStop,
                                              stops_count: usize,
-                                             extend_mode: WrGradientExtendMode,
-                                             tile_size: WrSize,
-                                             tile_spacing: WrSize) {
+                                             extend_mode: ExtendMode,
+                                             tile_size: LayoutSize,
+                                             tile_spacing: LayoutSize) {
     assert!(unsafe { is_in_main_thread() });
 
     let stops_slice = make_slice(stops, stops_count);
-    let stops_vector = stops_slice.iter().map(|x| x.into()).collect();
+    let stops_vector = stops_slice.to_owned();
 
     let gradient = state.frame_builder
                         .dl_builder
                         .create_radial_gradient(center.into(),
                                                 radius.into(),
                                                 stops_vector,
                                                 extend_mode.into());
     state.frame_builder
@@ -1667,72 +1368,72 @@ pub extern "C" fn wr_dp_push_radial_grad
                                Some(LocalClip::Rect(clip.into())),
                                gradient,
                                tile_size.into(),
                                tile_spacing.into());
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_box_shadow(state: &mut WrState,
-                                        rect: WrRect,
-                                        clip: WrRect,
-                                        box_bounds: WrRect,
-                                        offset: WrPoint,
-                                        color: WrColor,
+                                        rect: LayoutRect,
+                                        clip: LayoutRect,
+                                        box_bounds: LayoutRect,
+                                        offset: LayoutVector2D,
+                                        color: ColorF,
                                         blur_radius: f32,
                                         spread_radius: f32,
                                         border_radius: f32,
-                                        clip_mode: WrBoxShadowClipMode) {
+                                        clip_mode: BoxShadowClipMode) {
     assert!(unsafe { is_in_main_thread() });
 
     state.frame_builder
          .dl_builder
          .push_box_shadow(rect.into(),
                           Some(LocalClip::Rect(clip.into())),
                           box_bounds.into(),
-                          offset.into(),
+                          offset,
                           color.into(),
                           blur_radius,
                           spread_radius,
                           border_radius,
                           clip_mode);
 }
 
 #[no_mangle]
 pub unsafe extern "C" fn wr_api_finalize_builder(state: &mut WrState,
-                                                 content_size: &mut WrSize,
-                                                 dl_descriptor: &mut WrBuiltDisplayListDescriptor,
+                                                 content_size: &mut LayoutSize,
+                                                 dl_descriptor: &mut BuiltDisplayListDescriptor,
                                                  dl_data: &mut WrVecU8) {
     let frame_builder = mem::replace(&mut state.frame_builder,
                                      WebRenderFrameBuilder::new(state.pipeline_id,
-                                                                WrSize::zero()));
+                                                                LayoutSize::zero()));
     let (_, size, dl) = frame_builder.dl_builder.finalize();
-    *content_size = WrSize::new(size.width, size.height);
+    *content_size = LayoutSize::new(size.width, size.height);
     let (data, descriptor) = dl.into_data();
     *dl_data = WrVecU8::from_vec(data);
     *dl_descriptor = descriptor;
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_built_display_list(state: &mut WrState,
-                                                dl_descriptor: WrBuiltDisplayListDescriptor,
+                                                dl_descriptor: BuiltDisplayListDescriptor,
                                                 dl_data: &mut WrVecU8) {
     let dl_vec = mem::replace(dl_data, WrVecU8::from_vec(Vec::new())).to_vec();
 
     let dl = BuiltDisplayList::from_data(dl_vec, dl_descriptor);
 
     state.frame_builder.dl_builder.push_nested_display_list(&dl);
     let (data, _) = dl.into_data();
     mem::replace(dl_data, WrVecU8::from_vec(data));
 }
 
 // TODO: nical
 // Update for the new blob image interface changes.
 //
 extern "C" {
      // TODO: figure out the API for tiled blob images.
-     pub fn wr_moz2d_render_cb(blob: WrByteSlice,
+     pub fn wr_moz2d_render_cb(blob: ByteSlice,
                                width: u32,
                                height: u32,
-                               format: WrImageFormat,
+                               format: ImageFormat,
                                output: MutByteSlice)
                                -> bool;
 }
--- a/gfx/webrender_bindings/src/moz2d_renderer.rs
+++ b/gfx/webrender_bindings/src/moz2d_renderer.rs
@@ -1,10 +1,10 @@
 use webrender_api::*;
-use bindings::{WrByteSlice, MutByteSlice, wr_moz2d_render_cb};
+use bindings::{ByteSlice, MutByteSlice, wr_moz2d_render_cb};
 use rayon::ThreadPool;
 
 use std::collections::hash_map::{HashMap, Entry};
 use std::sync::mpsc::{channel, Sender, Receiver};
 use std::sync::Arc;
 
 pub struct Moz2dImageRenderer {
     blob_commands: HashMap<ImageKey, Arc<BlobImageData>>,
@@ -53,17 +53,17 @@ impl BlobImageRenderer for Moz2dImageRen
         self.workers.spawn(move || {
             let buf_size = (descriptor.width
                 * descriptor.height
                 * descriptor.format.bytes_per_pixel().unwrap()) as usize;
             let mut output = vec![255u8; buf_size];
 
             let result = unsafe {
                 if wr_moz2d_render_cb(
-                    WrByteSlice::new(&commands[..]),
+                    ByteSlice::new(&commands[..]),
                     descriptor.width,
                     descriptor.height,
                     descriptor.format,
                     MutByteSlice::new(output.as_mut_slice())
                 ) {
                     Ok(RasterizedBlobImage {
                         width: descriptor.width,
                         height: descriptor.height,
--- a/gfx/webrender_bindings/webrender_ffi.h
+++ b/gfx/webrender_bindings/webrender_ffi.h
@@ -43,31 +43,9 @@ void* get_proc_address_from_glcontext(vo
 #  define WR_DESTRUCTOR_SAFE_FUNC {}
 #endif
 
 #include "webrender_ffi_generated.h"
 
 #undef WR_FUNC
 #undef WR_DESTRUCTOR_SAFE_FUNC
 
-struct WrGlyphArray
-{
-  mozilla::gfx::Color color;
-  nsTArray<WrGlyphInstance> glyphs;
-
-  bool operator==(const WrGlyphArray& other) const
-  {
-    if (!(color == other.color) ||
-       (glyphs.Length() != other.glyphs.Length())) {
-      return false;
-    }
-
-    for (size_t i = 0; i < glyphs.Length(); i++) {
-      if (!(glyphs[i] == other.glyphs[i])) {
-        return false;
-      }
-    }
-
-    return true;
-  }
-};
-
 #endif // WR_h
--- a/gfx/webrender_bindings/webrender_ffi_generated.h
+++ b/gfx/webrender_bindings/webrender_ffi_generated.h
@@ -1,49 +1,115 @@
 /* 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/. */
 
-/* Generated with cbindgen:0.1.13 */
+/* Generated with cbindgen:0.1.18 */
 
 /* DO NOT MODIFY THIS MANUALLY! This file was generated using cbindgen.
  * To generate this file:
  *   1. Get the latest cbindgen using `cargo install --force cbindgen`
  *      a. Alternatively, you can clone `https://github.com/rlhunt/cbindgen` and use a tagged release
  *   2. Run `cbindgen toolkit/library/rust/ --crate webrender_bindings -o gfx/webrender_bindings/webrender_ffi_generated.h`
  */
 
 #include <cstdint>
 #include <cstdlib>
 
 extern "C" {
 
-enum class WrBorderStyle : uint32_t {
+namespace mozilla {
+namespace wr {
+
+enum class BorderStyle : uint32_t {
   None = 0,
   Solid = 1,
   Double = 2,
   Dotted = 3,
   Dashed = 4,
   Hidden = 5,
   Groove = 6,
   Ridge = 7,
   Inset = 8,
   Outset = 9,
 
   Sentinel /* this must be last for serialization purposes. */
 };
 
-enum class WrBoxShadowClipMode : uint32_t {
+enum class BoxShadowClipMode : uint32_t {
   None = 0,
   Outset = 1,
   Inset = 2,
 
   Sentinel /* this must be last for serialization purposes. */
 };
 
+enum class ExtendMode : uint32_t {
+  Clamp = 0,
+  Repeat = 1,
+
+  Sentinel /* this must be last for serialization purposes. */
+};
+
+enum class ImageFormat : uint32_t {
+  Invalid = 0,
+  A8 = 1,
+  RGB8 = 2,
+  BGRA8 = 3,
+  RGBAF32 = 4,
+  RG8 = 5,
+
+  Sentinel /* this must be last for serialization purposes. */
+};
+
+enum class ImageRendering : uint32_t {
+  Auto = 0,
+  CrispEdges = 1,
+  Pixelated = 2,
+
+  Sentinel /* this must be last for serialization purposes. */
+};
+
+enum class MixBlendMode : uint32_t {
+  Normal = 0,
+  Multiply = 1,
+  Screen = 2,
+  Overlay = 3,
+  Darken = 4,
+  Lighten = 5,
+  ColorDodge = 6,
+  ColorBurn = 7,
+  HardLight = 8,
+  SoftLight = 9,
+  Difference = 10,
+  Exclusion = 11,
+  Hue = 12,
+  Saturation = 13,
+  Color = 14,
+  Luminosity = 15,
+
+  Sentinel /* this must be last for serialization purposes. */
+};
+
+enum class RepeatMode : uint32_t {
+  Stretch = 0,
+  Repeat = 1,
+  Round = 2,
+  Space = 3,
+
+  Sentinel /* this must be last for serialization purposes. */
+};
+
+enum class TransformStyle : uint32_t {
+  Flat = 0,
+  Preserve3D = 1,
+
+  Sentinel /* this must be last for serialization purposes. */
+};
+
 enum class WrExternalImageBufferType : uint32_t {
   Texture2DHandle = 0,
   TextureRectHandle = 1,
   TextureExternalHandle = 2,
   ExternalBuffer = 3,
 
   Sentinel /* this must be last for serialization purposes. */
 };
@@ -64,127 +130,66 @@ enum class WrFilterOpType : uint32_t {
   Invert = 5,
   Opacity = 6,
   Saturate = 7,
   Sepia = 8,
 
   Sentinel /* this must be last for serialization purposes. */
 };
 
-enum class WrGradientExtendMode : uint32_t {
-  Clamp = 0,
-  Repeat = 1,
-
-  Sentinel /* this must be last for serialization purposes. */
-};
-
-enum class WrImageFormat : uint32_t {
-  Invalid = 0,
-  A8 = 1,
-  RGB8 = 2,
-  BGRA8 = 3,
-  RGBAF32 = 4,
-  RG8 = 5,
-
-  Sentinel /* this must be last for serialization purposes. */
-};
-
-enum class WrImageRendering : uint32_t {
-  Auto = 0,
-  CrispEdges = 1,
-  Pixelated = 2,
-
-  Sentinel /* this must be last for serialization purposes. */
-};
-
-enum class WrMixBlendMode : uint32_t {
-  Normal = 0,
-  Multiply = 1,
-  Screen = 2,
-  Overlay = 3,
-  Darken = 4,
-  Lighten = 5,
-  ColorDodge = 6,
-  ColorBurn = 7,
-  HardLight = 8,
-  SoftLight = 9,
-  Difference = 10,
-  Exclusion = 11,
-  Hue = 12,
-  Saturation = 13,
-  Color = 14,
-  Luminosity = 15,
-
-  Sentinel /* this must be last for serialization purposes. */
-};
-
-enum class WrRepeatMode : uint32_t {
-  Stretch = 0,
-  Repeat = 1,
-  Round = 2,
-  Space = 3,
-
-  Sentinel /* this must be last for serialization purposes. */
-};
-
-enum class WrTransformStyle : uint32_t {
-  Flat = 0,
-  Preserve3D = 1,
-
-  Sentinel /* this must be last for serialization purposes. */
-};
-
 enum class WrYuvColorSpace : uint32_t {
   Rec601 = 0,
   Rec709 = 1,
 
   Sentinel /* this must be last for serialization purposes. */
 };
 
-struct WrAPI;
+struct LayerPixel;
+
+struct RenderApi;
+
+struct Renderer;
 
 struct WrRenderedEpochs;
 
-struct WrRenderer;
-
 struct WrState;
 
 struct WrThreadPool;
 
 struct WrImageKey {
   uint32_t mNamespace;
   uint32_t mHandle;
 
   bool operator==(const WrImageKey& aOther) const {
     return mNamespace == aOther.mNamespace &&
            mHandle == aOther.mHandle;
   }
 };
 
 struct WrImageDescriptor {
-  WrImageFormat format;
+  ImageFormat format;
   uint32_t width;
   uint32_t height;
   uint32_t stride;
   bool is_opaque;
 
   bool operator==(const WrImageDescriptor& aOther) const {
     return format == aOther.format &&
            width == aOther.width &&
            height == aOther.height &&
            stride == aOther.stride &&
            is_opaque == aOther.is_opaque;
   }
 };
 
-struct WrByteSlice {
+struct ByteSlice {
   const uint8_t *buffer;
   size_t len;
 
-  bool operator==(const WrByteSlice& aOther) const {
+  bool operator==(const ByteSlice& aOther) const {
     return buffer == aOther.buffer &&
            len == aOther.len;
   }
 };
 
 struct WrExternalImageId {
   uint64_t mHandle;
 
@@ -222,31 +227,31 @@ struct WrPipelineId {
   uint32_t mHandle;
 
   bool operator==(const WrPipelineId& aOther) const {
     return mNamespace == aOther.mNamespace &&
            mHandle == aOther.mHandle;
   }
 };
 
-struct WrSize {
+struct LayoutSize {
   float width;
   float height;
 
-  bool operator==(const WrSize& aOther) const {
+  bool operator==(const LayoutSize& aOther) const {
     return width == aOther.width &&
            height == aOther.height;
   }
 };
 
-struct WrBuiltDisplayListDescriptor {
+struct BuiltDisplayListDescriptor {
   uint64_t builder_start_time;
   uint64_t builder_finish_time;
 
-  bool operator==(const WrBuiltDisplayListDescriptor& aOther) const {
+  bool operator==(const BuiltDisplayListDescriptor& aOther) const {
     return builder_start_time == aOther.builder_start_time &&
            builder_finish_time == aOther.builder_finish_time;
   }
 };
 
 struct WrVecU8 {
   uint8_t *data;
   size_t length;
@@ -264,178 +269,238 @@ struct WrOpacityProperty {
   float opacity;
 
   bool operator==(const WrOpacityProperty& aOther) const {
     return id == aOther.id &&
            opacity == aOther.opacity;
   }
 };
 
-struct WrMatrix {
-  float values[16];
+struct LayoutTransform {
+  float m11;
+  float m12;
+  float m13;
+  float m14;
+  float m21;
+  float m22;
+  float m23;
+  float m24;
+  float m31;
+  float m32;
+  float m33;
+  float m34;
+  float m41;
+  float m42;
+  float m43;
+  float m44;
+
+  bool operator==(const LayoutTransform& aOther) const {
+    return m11 == aOther.m11 &&
+           m12 == aOther.m12 &&
+           m13 == aOther.m13 &&
+           m14 == aOther.m14 &&
+           m21 == aOther.m21 &&
+           m22 == aOther.m22 &&
+           m23 == aOther.m23 &&
+           m24 == aOther.m24 &&
+           m31 == aOther.m31 &&
+           m32 == aOther.m32 &&
+           m33 == aOther.m33 &&
+           m34 == aOther.m34 &&
+           m41 == aOther.m41 &&
+           m42 == aOther.m42 &&
+           m43 == aOther.m43 &&
+           m44 == aOther.m44;
+  }
 };
 
 struct WrTransformProperty {
   uint64_t id;
-  WrMatrix transform;
+  LayoutTransform transform;
 };
 
 struct WrIdNamespace {
   uint32_t mHandle;
 
   bool operator==(const WrIdNamespace& aOther) const {
     return mHandle == aOther.mHandle;
   }
   bool operator<(const WrIdNamespace& aOther) const {
     return mHandle < aOther.mHandle;
   }
   bool operator<=(const WrIdNamespace& aOther) const {
     return mHandle <= aOther.mHandle;
   }
 };
 
-struct WrColor {
+struct ColorF {
   float r;
   float g;
   float b;
   float a;
 
-  bool operator==(const WrColor& aOther) const {
+  bool operator==(const ColorF& aOther) const {
     return r == aOther.r &&
            g == aOther.g &&
            b == aOther.b &&
            a == aOther.a;
   }
 };
 
-struct WrRect {
+struct TypedPoint2D_f32__LayerPixel {
   float x;
   float y;
+
+  bool operator==(const TypedPoint2D_f32__LayerPixel& aOther) const {
+    return x == aOther.x &&
+           y == aOther.y;
+  }
+};
+
+struct TypedSize2D_f32__LayerPixel {
   float width;
   float height;
 
-  bool operator==(const WrRect& aOther) const {
-    return x == aOther.x &&
-           y == aOther.y &&
-           width == aOther.width &&
+  bool operator==(const TypedSize2D_f32__LayerPixel& aOther) const {
+    return width == aOther.width &&
            height == aOther.height;
   }
 };
 
-struct WrBorderWidths {
+struct LayoutRect {
+  TypedPoint2D_f32__LayerPixel origin;
+  TypedSize2D_f32__LayerPixel size;
+
+  bool operator==(const LayoutRect& aOther) const {
+    return origin == aOther.origin &&
+           size == aOther.size;
+  }
+};
+
+struct BorderWidths {
   float left;
   float top;
   float right;
   float bottom;
 
-  bool operator==(const WrBorderWidths& aOther) const {
+  bool operator==(const BorderWidths& aOther) const {
     return left == aOther.left &&
            top == aOther.top &&
            right == aOther.right &&
            bottom == aOther.bottom;
   }
 };
 
-struct WrBorderSide {
-  WrColor color;
-  WrBorderStyle style;
+struct BorderSide {
+  ColorF color;
+  BorderStyle style;
 
-  bool operator==(const WrBorderSide& aOther) const {
+  bool operator==(const BorderSide& aOther) const {
     return color == aOther.color &&
            style == aOther.style;
   }
 };
 
-struct WrBorderRadius {
-  WrSize top_left;
-  WrSize top_right;
-  WrSize bottom_left;
-  WrSize bottom_right;
+struct BorderRadius {
+  LayoutSize top_left;
+  LayoutSize top_right;
+  LayoutSize bottom_left;
+  LayoutSize bottom_right;
 
-  bool operator==(const WrBorderRadius& aOther) const {
+  bool operator==(const BorderRadius& aOther) const {
     return top_left == aOther.top_left &&
            top_right == aOther.top_right &&
            bottom_left == aOther.bottom_left &&
            bottom_right == aOther.bottom_right;
   }
 };
 
-struct WrPoint {
+struct LayoutPoint {
   float x;
   float y;
 
-  bool operator==(const WrPoint& aOther) const {
+  bool operator==(const LayoutPoint& aOther) const {
     return x == aOther.x &&
            y == aOther.y;
   }
 };
 
-struct WrGradientStop {
+struct GradientStop {
   float offset;
-  WrColor color;
+  ColorF color;
 
-  bool operator==(const WrGradientStop& aOther) const {
+  bool operator==(const GradientStop& aOther) const {
     return offset == aOther.offset &&
            color == aOther.color;
   }
 };
 
-struct WrSideOffsets2Df32 {
+struct SideOffsets2D_f32 {
   float top;
   float right;
   float bottom;
   float left;
 
-  bool operator==(const WrSideOffsets2Df32& aOther) const {
+  bool operator==(const SideOffsets2D_f32& aOther) const {
     return top == aOther.top &&
            right == aOther.right &&
            bottom == aOther.bottom &&
            left == aOther.left;
   }
 };
 
-struct WrSideOffsets2Du32 {
+struct SideOffsets2D_u32 {
   uint32_t top;
   uint32_t right;
   uint32_t bottom;
   uint32_t left;
 
-  bool operator==(const WrSideOffsets2Du32& aOther) const {
+  bool operator==(const SideOffsets2D_u32& aOther) const {
     return top == aOther.top &&
            right == aOther.right &&
            bottom == aOther.bottom &&
            left == aOther.left;
   }
 };
 
-struct WrNinePatchDescriptor {
+struct NinePatchDescriptor {
   uint32_t width;
   uint32_t height;
-  WrSideOffsets2Du32 slice;
+  SideOffsets2D_u32 slice;
 
-  bool operator==(const WrNinePatchDescriptor& aOther) const {
+  bool operator==(const NinePatchDescriptor& aOther) const {
     return width == aOther.width &&
            height == aOther.height &&
            slice == aOther.slice;
   }
 };
 
+struct LayoutVector2D {
+  float x;
+  float y;
+
+  bool operator==(const LayoutVector2D& aOther) const {
+    return x == aOther.x &&
+           y == aOther.y;
+  }
+};
+
 struct WrComplexClipRegion {
-  WrRect rect;
-  WrBorderRadius radii;
+  LayoutRect rect;
+  BorderRadius radii;
 
   bool operator==(const WrComplexClipRegion& aOther) const {
     return rect == aOther.rect &&
            radii == aOther.radii;
   }
 };
 
 struct WrImageMask {
   WrImageKey image;
-  WrRect rect;
+  LayoutRect rect;
   bool repeat;
 
   bool operator==(const WrImageMask& aOther) const {
     return image == aOther.image &&
            rect == aOther.rect &&
            repeat == aOther.repeat;
   }
 };
@@ -445,21 +510,21 @@ struct WrFilterOp {
   float argument;
 
   bool operator==(const WrFilterOp& aOther) const {
     return filter_type == aOther.filter_type &&
            argument == aOther.argument;
   }
 };
 
-struct WrGlyphInstance {
+struct GlyphInstance {
   uint32_t index;
-  WrPoint point;
+  LayoutPoint point;
 
-  bool operator==(const WrGlyphInstance& aOther) const {
+  bool operator==(const GlyphInstance& aOther) const {
     return index == aOther.index &&
            point == aOther.point;
   }
 };
 
 struct MutByteSlice {
   uint8_t *buffer;
   size_t len;
@@ -525,130 +590,130 @@ struct WrExternalImageHandler {
 /* DO NOT MODIFY THIS MANUALLY! This file was generated using cbindgen.
  * To generate this file:
  *   1. Get the latest cbindgen using `cargo install --force cbindgen`
  *      a. Alternatively, you can clone `https://github.com/rlhunt/cbindgen` and use a tagged release
  *   2. Run `cbindgen toolkit/library/rust/ --crate webrender_bindings -o gfx/webrender_bindings/webrender_ffi_generated.h`
  */
 
 WR_INLINE
-void wr_api_add_blob_image(WrAPI *aApi,
+void wr_api_add_blob_image(RenderApi *aApi,
                            WrImageKey aImageKey,
                            const WrImageDescriptor *aDescriptor,
-                           WrByteSlice aBytes)
+                           ByteSlice aBytes)
 WR_FUNC;
 
 WR_INLINE
-void wr_api_add_external_image(WrAPI *aApi,
+void wr_api_add_external_image(RenderApi *aApi,
                                WrImageKey aImageKey,
                                const WrImageDescriptor *aDescriptor,
                                WrExternalImageId aExternalImageId,
                                WrExternalImageBufferType aBufferType,
                                uint8_t aChannelIndex)
 WR_FUNC;
 
 WR_INLINE
-void wr_api_add_external_image_buffer(WrAPI *aApi,
+void wr_api_add_external_image_buffer(RenderApi *aApi,
                                       WrImageKey aImageKey,
                                       const WrImageDescriptor *aDescriptor,
                                       WrExternalImageId aExternalImageId)
 WR_FUNC;
 
 WR_INLINE
-void wr_api_add_image(WrAPI *aApi,
+void wr_api_add_image(RenderApi *aApi,
                       WrImageKey aImageKey,
                       const WrImageDescriptor *aDescriptor,
-                      WrByteSlice aBytes)
+                      ByteSlice aBytes)
 WR_FUNC;
 
 WR_INLINE
-void wr_api_add_raw_font(WrAPI *aApi,
+void wr_api_add_raw_font(RenderApi *aApi,
                          WrFontKey aKey,
                          uint8_t *aFontBuffer,
                          size_t aBufferSize,
                          uint32_t aIndex)
 WR_FUNC;
 
 WR_INLINE
-void wr_api_clear_root_display_list(WrAPI *aApi,
+void wr_api_clear_root_display_list(RenderApi *aApi,
                                     WrEpoch aEpoch,
                                     WrPipelineId aPipelineId)
 WR_FUNC;
 
 WR_INLINE
-void wr_api_delete(WrAPI *aApi)
+void wr_api_delete(RenderApi *aApi)
 WR_DESTRUCTOR_SAFE_FUNC;
 
 WR_INLINE
-void wr_api_delete_font(WrAPI *aApi,
+void wr_api_delete_font(RenderApi *aApi,
                         WrFontKey aKey)
 WR_FUNC;
 
 WR_INLINE
-void wr_api_delete_image(WrAPI *aApi,
+void wr_api_delete_image(RenderApi *aApi,
                          WrImageKey aKey)
 WR_FUNC;
 
 WR_INLINE
 void wr_api_finalize_builder(WrState *aState,
-                             WrSize *aContentSize,
-                             WrBuiltDisplayListDescriptor *aDlDescriptor,
+                             LayoutSize *aContentSize,
+                             BuiltDisplayListDescriptor *aDlDescriptor,
                              WrVecU8 *aDlData)
 WR_FUNC;
 
 WR_INLINE
-void wr_api_generate_frame(WrAPI *aApi)
+void wr_api_generate_frame(RenderApi *aApi)
 WR_FUNC;
 
 WR_INLINE
-void wr_api_generate_frame_with_properties(WrAPI *aApi,
+void wr_api_generate_frame_with_properties(RenderApi *aApi,
                                            const WrOpacityProperty *aOpacityArray,
                                            size_t aOpacityCount,
                                            const WrTransformProperty *aTransformArray,
                                            size_t aTransformCount)
 WR_FUNC;
 
 WR_INLINE
-WrIdNamespace wr_api_get_namespace(WrAPI *aApi)
+WrIdNamespace wr_api_get_namespace(RenderApi *aApi)
 WR_FUNC;
 
 WR_INLINE
-void wr_api_send_external_event(WrAPI *aApi,
+void wr_api_send_external_event(RenderApi *aApi,
                                 size_t aEvt)
 WR_DESTRUCTOR_SAFE_FUNC;
 
 WR_INLINE
-void wr_api_set_root_display_list(WrAPI *aApi,
-                                  WrColor aColor,
+void wr_api_set_root_display_list(RenderApi *aApi,
+                                  ColorF aColor,
                                   WrEpoch aEpoch,
                                   float aViewportWidth,
                                   float aViewportHeight,
                                   WrPipelineId aPipelineId,
-                                  WrSize aContentSize,
-                                  WrBuiltDisplayListDescriptor aDlDescriptor,
+                                  LayoutSize aContentSize,
+                                  BuiltDisplayListDescriptor aDlDescriptor,
                                   uint8_t *aDlData,
                                   size_t aDlSize)
 WR_FUNC;
 
 WR_INLINE
-void wr_api_set_root_pipeline(WrAPI *aApi,
+void wr_api_set_root_pipeline(RenderApi *aApi,
                               WrPipelineId aPipelineId)
 WR_FUNC;
 
 WR_INLINE
-void wr_api_set_window_parameters(WrAPI *aApi,
+void wr_api_set_window_parameters(RenderApi *aApi,
                                   int32_t aWidth,
                                   int32_t aHeight)
 WR_FUNC;
 
 WR_INLINE
-void wr_api_update_image(WrAPI *aApi,
+void wr_api_update_image(RenderApi *aApi,
                          WrImageKey aKey,
                          const WrImageDescriptor *aDescriptor,
-                         WrByteSlice aBytes)
+                         ByteSlice aBytes)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_begin(WrState *aState,
                  uint32_t aWidth,
                  uint32_t aHeight)
 WR_FUNC;
 
@@ -669,272 +734,272 @@ void wr_dp_pop_scroll_layer(WrState *aSt
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_pop_stacking_context(WrState *aState)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_border(WrState *aState,
-                       WrRect aRect,
-                       WrRect aClip,
-                       WrBorderWidths aWidths,
-                       WrBorderSide aTop,
-                       WrBorderSide aRight,
-                       WrBorderSide aBottom,
-                       WrBorderSide aLeft,
-                       WrBorderRadius aRadius)
+                       LayoutRect aRect,
+                       LayoutRect aClip,
+                       BorderWidths aWidths,
+                       BorderSide aTop,
+                       BorderSide aRight,
+                       BorderSide aBottom,
+                       BorderSide aLeft,
+                       BorderRadius aRadius)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_border_gradient(WrState *aState,
-                                WrRect aRect,
-                                WrRect aClip,
-                                WrBorderWidths aWidths,
-                                WrPoint aStartPoint,
-                                WrPoint aEndPoint,
-                                const WrGradientStop *aStops,
+                                LayoutRect aRect,
+                                LayoutRect aClip,
+                                BorderWidths aWidths,
+                                LayoutPoint aStartPoint,
+                                LayoutPoint aEndPoint,
+                                const GradientStop *aStops,
                                 size_t aStopsCount,
-                                WrGradientExtendMode aExtendMode,
-                                WrSideOffsets2Df32 aOutset)
+                                ExtendMode aExtendMode,
+                                SideOffsets2D_f32 aOutset)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_border_image(WrState *aState,
-                             WrRect aRect,
-                             WrRect aClip,
-                             WrBorderWidths aWidths,
+                             LayoutRect aRect,
+                             LayoutRect aClip,
+                             BorderWidths aWidths,
                              WrImageKey aImage,
-                             WrNinePatchDescriptor aPatch,
-                             WrSideOffsets2Df32 aOutset,
-                             WrRepeatMode aRepeatHorizontal,
-                             WrRepeatMode aRepeatVertical)
+                             NinePatchDescriptor aPatch,
+                             SideOffsets2D_f32 aOutset,
+                             RepeatMode aRepeatHorizontal,
+                             RepeatMode aRepeatVertical)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_border_radial_gradient(WrState *aState,
-                                       WrRect aRect,
-                                       WrRect aClip,
-                                       WrBorderWidths aWidths,
-                                       WrPoint aCenter,
-                                       WrSize aRadius,
-                                       const WrGradientStop *aStops,
+                                       LayoutRect aRect,
+                                       LayoutRect aClip,
+                                       BorderWidths aWidths,
+                                       LayoutPoint aCenter,
+                                       LayoutSize aRadius,
+                                       const GradientStop *aStops,
                                        size_t aStopsCount,
-                                       WrGradientExtendMode aExtendMode,
-                                       WrSideOffsets2Df32 aOutset)
+                                       ExtendMode aExtendMode,
+                                       SideOffsets2D_f32 aOutset)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_box_shadow(WrState *aState,
-                           WrRect aRect,
-                           WrRect aClip,
-                           WrRect aBoxBounds,
-                           WrPoint aOffset,
-                           WrColor aColor,
+                           LayoutRect aRect,
+                           LayoutRect aClip,
+                           LayoutRect aBoxBounds,
+                           LayoutVector2D aOffset,
+                           ColorF aColor,
                            float aBlurRadius,
                            float aSpreadRadius,
                            float aBorderRadius,
-                           WrBoxShadowClipMode aClipMode)
+                           BoxShadowClipMode aClipMode)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_built_display_list(WrState *aState,
-                                   WrBuiltDisplayListDescriptor aDlDescriptor,
+                                   BuiltDisplayListDescriptor aDlDescriptor,
                                    WrVecU8 *aDlData)
 WR_FUNC;
 
 WR_INLINE
 uint64_t wr_dp_push_clip(WrState *aState,
-                         WrRect aRect,
+                         LayoutRect aRect,
                          const WrComplexClipRegion *aComplex,
                          size_t aComplexCount,
                          const WrImageMask *aMask)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_clip_and_scroll_info(WrState *aState,
                                      uint64_t aScrollId,
                                      const uint64_t *aClipId)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_iframe(WrState *aState,
-                       WrRect aRect,
+                       LayoutRect aRect,
                        WrPipelineId aPipelineId)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_image(WrState *aState,
-                      WrRect aBounds,
-                      WrRect aClip,
-                      WrSize aStretchSize,
-                      WrSize aTileSpacing,
-                      WrImageRendering aImageRendering,
+                      LayoutRect aBounds,
+                      LayoutRect aClip,
+                      LayoutSize aStretchSize,
+                      LayoutSize aTileSpacing,
+                      ImageRendering aImageRendering,
                       WrImageKey aKey)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_linear_gradient(WrState *aState,
-                                WrRect aRect,
-                                WrRect aClip,
-                                WrPoint aStartPoint,
-                                WrPoint aEndPoint,
-                                const WrGradientStop *aStops,
+                                LayoutRect aRect,
+                                LayoutRect aClip,
+                                LayoutPoint aStartPoint,
+                                LayoutPoint aEndPoint,
+                                const GradientStop *aStops,
                                 size_t aStopsCount,
-                                WrGradientExtendMode aExtendMode,
-                                WrSize aTileSize,
-                                WrSize aTileSpacing)
+                                ExtendMode aExtendMode,
+                                LayoutSize aTileSize,
+                                LayoutSize aTileSpacing)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_radial_gradient(WrState *aState,
-                                WrRect aRect,
-                                WrRect aClip,
-                                WrPoint aCenter,
-                                WrSize aRadius,
-                                const WrGradientStop *aStops,
+                                LayoutRect aRect,
+                                LayoutRect aClip,
+                                LayoutPoint aCenter,
+                                LayoutSize aRadius,
+                                const GradientStop *aStops,
                                 size_t aStopsCount,
-                                WrGradientExtendMode aExtendMode,
-                                WrSize aTileSize,
-                                WrSize aTileSpacing)
+                                ExtendMode aExtendMode,
+                                LayoutSize aTileSize,
+                                LayoutSize aTileSpacing)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_rect(WrState *aState,
-                     WrRect aRect,
-                     WrRect aClip,
-                     WrColor aColor)
+                     LayoutRect aRect,
+                     LayoutRect aClip,
+                     ColorF aColor)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_scroll_layer(WrState *aState,
                              uint64_t aScrollId,
-                             WrRect aContentRect,
-                             WrRect aClipRect)
+                             LayoutRect aContentRect,
+                             LayoutRect aClipRect)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_stacking_context(WrState *aState,
-                                 WrRect aBounds,
+                                 LayoutRect aBounds,
                                  uint64_t aAnimationId,
                                  const float *aOpacity,
-                                 const WrMatrix *aTransform,
-                                 WrTransformStyle aTransformStyle,
-                                 WrMixBlendMode aMixBlendMode,
+                                 const LayoutTransform *aTransform,
+                                 TransformStyle aTransformStyle,
+                                 MixBlendMode aMixBlendMode,
                                  const WrFilterOp *aFilters,
                                  size_t aFilterCount)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_text(WrState *aState,
-                     WrRect aBounds,
-                     WrRect aClip,
-                     WrColor aColor,
+                     LayoutRect aBounds,
+                     LayoutRect aClip,
+                     ColorF aColor,
                      WrFontKey aFontKey,
-                     const WrGlyphInstance *aGlyphs,
+                     const GlyphInstance *aGlyphs,
                      uint32_t aGlyphCount,
                      float aGlyphSize)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_yuv_NV12_image(WrState *aState,
-                               WrRect aBounds,
-                               WrRect aClip,
+                               LayoutRect aBounds,
+                               LayoutRect aClip,
                                WrImageKey aImageKey0,
                                WrImageKey aImageKey1,
                                WrYuvColorSpace aColorSpace,
-                               WrImageRendering aImageRendering)
+                               ImageRendering aImageRendering)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_yuv_interleaved_image(WrState *aState,
-                                      WrRect aBounds,
-                                      WrRect aClip,
+                                      LayoutRect aBounds,
+                                      LayoutRect aClip,
                                       WrImageKey aImageKey0,
                                       WrYuvColorSpace aColorSpace,
-                                      WrImageRendering aImageRendering)
+                                      ImageRendering aImageRendering)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_yuv_planar_image(WrState *aState,
-                                 WrRect aBounds,
-                                 WrRect aClip,
+                                 LayoutRect aBounds,
+                                 LayoutRect aClip,
                                  WrImageKey aImageKey0,
                                  WrImageKey aImageKey1,
                                  WrImageKey aImageKey2,
                                  WrYuvColorSpace aColorSpace,
-                                 WrImageRendering aImageRendering)
+                                 ImageRendering aImageRendering)
 WR_FUNC;
 
 WR_INLINE
 void wr_rendered_epochs_delete(WrRenderedEpochs *aPipelineEpochs)
 WR_DESTRUCTOR_SAFE_FUNC;
 
 WR_INLINE
 bool wr_rendered_epochs_next(WrRenderedEpochs *aPipelineEpochs,
                              WrPipelineId *aOutPipeline,
                              WrEpoch *aOutEpoch)
 WR_FUNC;
 
 WR_INLINE
-bool wr_renderer_current_epoch(WrRenderer *aRenderer,
+bool wr_renderer_current_epoch(Renderer *aRenderer,
                                WrPipelineId aPipelineId,
                                WrEpoch *aOutEpoch)
 WR_FUNC;
 
 WR_INLINE
-void wr_renderer_delete(WrRenderer *aRenderer)
+void wr_renderer_delete(Renderer *aRenderer)
 WR_DESTRUCTOR_SAFE_FUNC;
 
 WR_INLINE
-WrRenderedEpochs *wr_renderer_flush_rendered_epochs(WrRenderer *aRenderer)
+WrRenderedEpochs *wr_renderer_flush_rendered_epochs(Renderer *aRenderer)
 WR_FUNC;
 
 WR_INLINE
-void wr_renderer_readback(WrRenderer *aRenderer,
+void wr_renderer_readback(Renderer *aRenderer,
                           uint32_t aWidth,
                           uint32_t aHeight,
                           uint8_t *aDstBuffer,
                           size_t aBufferSize)
 WR_FUNC;
 
 WR_INLINE
-void wr_renderer_render(WrRenderer *aRenderer,
+void wr_renderer_render(Renderer *aRenderer,
                         uint32_t aWidth,
                         uint32_t aHeight)
 WR_FUNC;
 
 WR_INLINE
-void wr_renderer_set_external_image_handler(WrRenderer *aRenderer,
+void wr_renderer_set_external_image_handler(Renderer *aRenderer,
                                             WrExternalImageHandler *aExternalImageHandler)
 WR_FUNC;
 
 WR_INLINE
-void wr_renderer_set_profiler_enabled(WrRenderer *aRenderer,
+void wr_renderer_set_profiler_enabled(Renderer *aRenderer,
                                       bool aEnabled)
 WR_FUNC;
 
 WR_INLINE
-void wr_renderer_update(WrRenderer *aRenderer)
+void wr_renderer_update(Renderer *aRenderer)
 WR_FUNC;
 
 WR_INLINE
-void wr_scroll_layer_with_id(WrAPI *aApi,
+void wr_scroll_layer_with_id(RenderApi *aApi,
                              WrPipelineId aPipelineId,
                              uint64_t aScrollId,
-                             WrPoint aNewScrollOrigin)
+                             LayoutPoint aNewScrollOrigin)
 WR_FUNC;
 
 WR_INLINE
 void wr_state_delete(WrState *aState)
 WR_DESTRUCTOR_SAFE_FUNC;
 
 WR_INLINE
 WrState *wr_state_new(WrPipelineId aPipelineId,
-                      WrSize aContentSize)
+                      LayoutSize aContentSize)
 WR_FUNC;
 
 WR_INLINE
 void wr_thread_pool_delete(WrThreadPool *aThreadPool)
 WR_DESTRUCTOR_SAFE_FUNC;
 
 WR_INLINE
 WrThreadPool *wr_thread_pool_new()
@@ -946,20 +1011,23 @@ WR_FUNC;
 
 WR_INLINE
 bool wr_window_new(WrWindowId aWindowId,
                    uint32_t aWindowWidth,
                    uint32_t aWindowHeight,
                    void *aGlContext,
                    WrThreadPool *aThreadPool,
                    bool aEnableProfiler,
-                   WrAPI **aOutApi,
-                   WrRenderer **aOutRenderer)
+                   RenderApi **aOutApi,
+                   Renderer **aOutRenderer)
 WR_FUNC;
 
+} // namespace wr
+} // namespace mozilla
+
 } // extern "C"
 
 /* DO NOT MODIFY THIS MANUALLY! This file was generated using cbindgen.
  * To generate this file:
  *   1. Get the latest cbindgen using `cargo install --force cbindgen`
  *      a. Alternatively, you can clone `https://github.com/rlhunt/cbindgen` and use a tagged release
  *   2. Run `cbindgen toolkit/library/rust/ --crate webrender_bindings -o gfx/webrender_bindings/webrender_ffi_generated.h`
  */
--- a/image/IDecodingTask.cpp
+++ b/image/IDecodingTask.cpp
@@ -8,95 +8,134 @@
 #include "gfxPrefs.h"
 #include "nsThreadUtils.h"
 
 #include "Decoder.h"
 #include "DecodePool.h"
 #include "RasterImage.h"
 #include "SurfaceCache.h"
 
+#include "mozilla/SystemGroup.h"
+
 namespace mozilla {
 
 using gfx::IntRect;
 
 namespace image {
 
 ///////////////////////////////////////////////////////////////////////////////
 // Helpers for sending notifications to the image associated with a decoder.
 ///////////////////////////////////////////////////////////////////////////////
 
-/* static */ void
+void
+IDecodingTask::EnsureHasEventTarget(NotNull<RasterImage*> aImage)
+{
+  if (!mEventTarget) {
+    // We determine the event target as late as possible, at the first dispatch
+    // time, because the observers bound to an imgRequest will affect it.
+    // We cache it rather than query for the event target each time because the
+    // event target can change. We don't want to risk events being executed in
+    // a different order than they are dispatched, which can happen if we
+    // selected scheduler groups which have no ordering guarantees relative to
+    // each other (e.g. it moves from scheduler group A for doc group DA to
+    // scheduler group B for doc group DB due to changing observers -- if we
+    // dispatched the first event on A, and the second on B, we don't know which
+    // will execute first.)
+    RefPtr<ProgressTracker> tracker = aImage->GetProgressTracker();
+    if (tracker) {
+      mEventTarget = tracker->GetEventTarget();
+    } else {
+      mEventTarget = SystemGroup::EventTargetFor(TaskCategory::Other);
+    }
+  }
+}
+
+bool
+IDecodingTask::IsOnEventTarget() const
+{
+  // This is essentially equivalent to NS_IsOnMainThread() because all of the
+  // event targets are for the main thread (although perhaps with a different
+  // label / scheduler group). The observers in ProgressTracker may have
+  // different event targets from this, so this is just a best effort guess.
+  bool current = false;
+  mEventTarget->IsOnCurrentThread(&current);
+  return current;
+}
+
+void
 IDecodingTask::NotifyProgress(NotNull<RasterImage*> aImage,
                               NotNull<Decoder*> aDecoder)
 {
   MOZ_ASSERT(aDecoder->HasProgress() && !aDecoder->IsMetadataDecode());
+  EnsureHasEventTarget(aImage);
 
   // Capture the decoder's state. If we need to notify asynchronously, it's
   // important that we don't wait until the lambda actually runs to capture the
   // state that we're going to notify. That would both introduce data races on
   // the decoder's state and cause inconsistencies between the NotifyProgress()
   // calls we make off-main-thread and the notifications that RasterImage
   // actually receives, which would cause bugs.
   Progress progress = aDecoder->TakeProgress();
   IntRect invalidRect = aDecoder->TakeInvalidRect();
   Maybe<uint32_t> frameCount = aDecoder->TakeCompleteFrameCount();
   DecoderFlags decoderFlags = aDecoder->GetDecoderFlags();
   SurfaceFlags surfaceFlags = aDecoder->GetSurfaceFlags();
 
   // Synchronously notify if we can.
-  if (NS_IsMainThread() && !(decoderFlags & DecoderFlags::ASYNC_NOTIFY)) {
+  if (IsOnEventTarget() && !(decoderFlags & DecoderFlags::ASYNC_NOTIFY)) {
     aImage->NotifyProgress(progress, invalidRect, frameCount,
                            decoderFlags, surfaceFlags);
     return;
   }
 
   // We're forced to notify asynchronously.
   NotNull<RefPtr<RasterImage>> image = aImage;
-  NS_DispatchToMainThread(NS_NewRunnableFunction(
-                            "IDecodingTask::NotifyProgress",
-                            [=]() -> void {
+  mEventTarget->Dispatch(NS_NewRunnableFunction(
+                           "IDecodingTask::NotifyProgress",
+                           [=]() -> void {
     image->NotifyProgress(progress, invalidRect, frameCount,
                           decoderFlags, surfaceFlags);
-  }));
+  }), NS_DISPATCH_NORMAL);
 }
 
-/* static */ void
+void
 IDecodingTask::NotifyDecodeComplete(NotNull<RasterImage*> aImage,
                                     NotNull<Decoder*> aDecoder)
 {
   MOZ_ASSERT(aDecoder->HasError() || !aDecoder->InFrame(),
              "Decode complete in the middle of a frame?");
+  EnsureHasEventTarget(aImage);
 
   // Capture the decoder's state.
   DecoderFinalStatus finalStatus = aDecoder->FinalStatus();
   ImageMetadata metadata = aDecoder->GetImageMetadata();
   DecoderTelemetry telemetry = aDecoder->Telemetry();
   Progress progress = aDecoder->TakeProgress();
   IntRect invalidRect = aDecoder->TakeInvalidRect();
   Maybe<uint32_t> frameCount = aDecoder->TakeCompleteFrameCount();
   DecoderFlags decoderFlags = aDecoder->GetDecoderFlags();
   SurfaceFlags surfaceFlags = aDecoder->GetSurfaceFlags();
 
   // Synchronously notify if we can.
-  if (NS_IsMainThread() && !(decoderFlags & DecoderFlags::ASYNC_NOTIFY)) {
+  if (IsOnEventTarget() && !(decoderFlags & DecoderFlags::ASYNC_NOTIFY)) {
     aImage->NotifyDecodeComplete(finalStatus, metadata, telemetry, progress,
                                  invalidRect, frameCount, decoderFlags,
                                  surfaceFlags);
     return;
   }
 
   // We're forced to notify asynchronously.
   NotNull<RefPtr<RasterImage>> image = aImage;
-  NS_DispatchToMainThread(NS_NewRunnableFunction(
-                            "IDecodingTask::NotifyDecodeComplete",
-                            [=]() -> void {
+  mEventTarget->Dispatch(NS_NewRunnableFunction(
+                           "IDecodingTask::NotifyDecodeComplete",
+                           [=]() -> void {
     image->NotifyDecodeComplete(finalStatus, metadata, telemetry, progress,
                                 invalidRect, frameCount, decoderFlags,
                                 surfaceFlags);
-  }));
+  }), NS_DISPATCH_NORMAL);
 }
 
 
 ///////////////////////////////////////////////////////////////////////////////
 // IDecodingTask implementation.
 ///////////////////////////////////////////////////////////////////////////////
 
 void
--- a/image/IDecodingTask.h
+++ b/image/IDecodingTask.h
@@ -45,25 +45,32 @@ public:
   /// @return a priority hint that DecodePool can use when scheduling this task.
   virtual TaskPriority Priority() const = 0;
 
   /// A default implementation of IResumable which resubmits the task to the
   /// DecodePool. Subclasses can override this if they need different behavior.
   void Resume() override;
 
 protected:
+  virtual ~IDecodingTask() { }
+
   /// Notify @aImage of @aDecoder's progress.
-  static void NotifyProgress(NotNull<RasterImage*> aImage,
-                             NotNull<Decoder*> aDecoder);
+  void NotifyProgress(NotNull<RasterImage*> aImage,
+                      NotNull<Decoder*> aDecoder);
 
   /// Notify @aImage that @aDecoder has finished.
-  static void NotifyDecodeComplete(NotNull<RasterImage*> aImage,
-                                   NotNull<Decoder*> aDecoder);
+  void NotifyDecodeComplete(NotNull<RasterImage*> aImage,
+                            NotNull<Decoder*> aDecoder);
 
-  virtual ~IDecodingTask() { }
+private:
+  void EnsureHasEventTarget(NotNull<RasterImage*> aImage);
+
+  bool IsOnEventTarget() const;
+
+  nsCOMPtr<nsIEventTarget> mEventTarget;
 };
 
 
 /**
  * An IDecodingTask implementation for metadata decodes of images.
  */
 class MetadataDecodingTask final : public IDecodingTask
 {
--- a/image/IProgressObserver.h
+++ b/image/IProgressObserver.h
@@ -5,16 +5,18 @@
 
 #ifndef mozilla_image_IProgressObserver_h
 #define mozilla_image_IProgressObserver_h
 
 #include "mozilla/WeakPtr.h"
 #include "nsISupports.h"
 #include "nsRect.h"
 
+class nsIEventTarget;
+
 namespace mozilla {
 namespace image {
 
 /**
  * An interface for observing changes to image state, as reported by
  * ProgressTracker.
  *
  * This is the ImageLib-internal version of imgINotificationObserver,
@@ -42,16 +44,21 @@ public:
   virtual void BlockOnload() = 0;
   virtual void UnblockOnload() = 0;
 
   // Other, internal-only methods:
   virtual void SetHasImage() = 0;
   virtual bool NotificationsDeferred() const = 0;
   virtual void SetNotificationsDeferred(bool aDeferNotifications) = 0;
 
+  virtual already_AddRefed<nsIEventTarget> GetEventTarget() const
+  {
+    return nullptr;
+  }
+
 protected:
   virtual ~IProgressObserver() { }
 };
 
 } // namespace image
 } // namespace mozilla
 
 #endif // mozilla_image_IProgressObserver_h
--- a/image/ProgressTracker.cpp
+++ b/image/ProgressTracker.cpp
@@ -11,16 +11,17 @@
 #include "imgINotificationObserver.h"
 #include "imgIRequest.h"
 #include "Image.h"
 #include "nsNetUtil.h"
 #include "nsIObserverService.h"
 
 #include "mozilla/Assertions.h"
 #include "mozilla/Services.h"
+#include "mozilla/SystemGroup.h"
 
 using mozilla::WeakPtr;
 
 namespace mozilla {
 namespace image {
 
 static void
 CheckProgressConsistency(Progress aOldProgress, Progress aNewProgress, bool aIsMultipart)
@@ -64,29 +65,39 @@ CheckProgressConsistency(Progress aOldPr
   if (aNewProgress & FLAG_LAST_PART_COMPLETE) {
     MOZ_ASSERT(aNewProgress & FLAG_LOAD_COMPLETE);
   }
   if (aNewProgress & FLAG_HAS_ERROR) {
     // No preconditions.
   }
 }
 
+ProgressTracker::ProgressTracker()
+  : mMutex("ProgressTracker::mMutex")
+  , mImage(nullptr)
+  , mEventTarget(WrapNotNull(nsCOMPtr<nsIEventTarget>(SystemGroup::EventTargetFor(TaskCategory::Other))))
+  , mObserversWithTargets(0)
+  , mObservers(new ObserverTable)
+  , mProgress(NoProgress)
+  , mIsMultipart(false)
+{ }
+
 void
 ProgressTracker::SetImage(Image* aImage)
 {
-  MutexAutoLock lock(mImageMutex);
+  MutexAutoLock lock(mMutex);
   MOZ_ASSERT(aImage, "Setting null image");
   MOZ_ASSERT(!mImage, "Setting image when we already have one");
   mImage = aImage;
 }
 
 void
 ProgressTracker::ResetImage()
 {
-  MutexAutoLock lock(mImageMutex);
+  MutexAutoLock lock(mMutex);
   MOZ_ASSERT(mImage, "Resetting image when it's already null!");
   mImage = nullptr;
 }
 
 uint32_t
 ProgressTracker::GetImageStatus() const
 {
   uint32_t status = imgIRequest::STATUS_NONE;
@@ -188,17 +199,17 @@ ProgressTracker::Notify(IProgressObserve
   // unnecessarily delay onload.
   AsyncNotifyRunnable* runnable =
     static_cast<AsyncNotifyRunnable*>(mRunnable.get());
 
   if (runnable) {
     runnable->AddObserver(aObserver);
   } else {
     mRunnable = new AsyncNotifyRunnable(this, aObserver);
-    NS_DispatchToCurrentThread(mRunnable);
+    mEventTarget->Dispatch(mRunnable, NS_DISPATCH_NORMAL);
   }
 }
 
 // A helper class to allow us to call SyncNotify asynchronously for a given,
 // fixed, state.
 class AsyncNotifyCurrentStateRunnable : public Runnable
 {
   public:
@@ -246,17 +257,17 @@ ProgressTracker::NotifyCurrentState(IPro
     LOG_FUNC_WITH_PARAM(gImgLog,
                         "ProgressTracker::NotifyCurrentState", "uri", spec.get());
   }
 
   aObserver->SetNotificationsDeferred(true);
 
   nsCOMPtr<nsIRunnable> ev = new AsyncNotifyCurrentStateRunnable(this,
                                                                  aObserver);
-  NS_DispatchToCurrentThread(ev);
+  mEventTarget->Dispatch(ev.forget(), NS_DISPATCH_NORMAL);
 }
 
 /**
  * ImageObserverNotifier is a helper type that abstracts over the difference
  * between sending notifications to all of the observers in an ObserverTable,
  * and sending them to a single observer. This allows the same notification code
  * to be used for both cases.
  */
@@ -443,42 +454,93 @@ ProgressTracker::EmulateRequestFinished(
     aObserver->UnblockOnload();
   }
 
   if (!(mProgress & FLAG_LOAD_COMPLETE)) {
     aObserver->OnLoadComplete(true);
   }
 }
 
+already_AddRefed<nsIEventTarget>
+ProgressTracker::GetEventTarget() const
+{
+  MutexAutoLock lock(mMutex);
+  nsCOMPtr<nsIEventTarget> target = mEventTarget;
+  return target.forget();
+}
+
 void
 ProgressTracker::AddObserver(IProgressObserver* aObserver)
 {
   MOZ_ASSERT(NS_IsMainThread());
   RefPtr<IProgressObserver> observer = aObserver;
 
+  nsCOMPtr<nsIEventTarget> target = observer->GetEventTarget();
+  if (target) {
+    if (mObserversWithTargets == 0) {
+      // On the first observer with a target (i.e. listener), always accept its
+      // event target; this may be for a specific DocGroup, or it may be the
+      // unlabelled main thread target.
+      MutexAutoLock lock(mMutex);
+      mEventTarget = WrapNotNull(target);
+    } else if (mEventTarget.get() != target.get()) {
+      // If a subsequent observer comes in with a different target, we need to
+      // switch to use the unlabelled main thread target, if we haven't already.
+      MutexAutoLock lock(mMutex);
+      nsCOMPtr<nsIEventTarget> mainTarget(do_GetMainThread());
+      mEventTarget = WrapNotNull(mainTarget);
+    }
+    ++mObserversWithTargets;
+  }
+
   mObservers.Write([=](ObserverTable* aTable) {
     MOZ_ASSERT(!aTable->Get(observer, nullptr),
                "Adding duplicate entry for image observer");
 
     WeakPtr<IProgressObserver> weakPtr = observer.get();
     aTable->Put(observer, weakPtr);
   });
+
+  MOZ_ASSERT(mObserversWithTargets <= ObserverCount());
 }
 
 bool
 ProgressTracker::RemoveObserver(IProgressObserver* aObserver)
 {
   MOZ_ASSERT(NS_IsMainThread());
   RefPtr<IProgressObserver> observer = aObserver;
 
   // Remove the observer from the list.
-  bool removed = mObservers.Write([=](ObserverTable* aTable) {
+  bool removed = mObservers.Write([observer](ObserverTable* aTable) {
     return aTable->Remove(observer);
   });
 
+  // Sometimes once an image is decoded, and all of its observers removed, a new
+  // document may request the same image. Thus we need to clear our event target
+  // state when the last observer is removed, so that we select the most
+  // appropriate event target when a new observer is added. Since the event
+  // target may have changed (e.g. due to the scheduler group going away before
+  // we were removed), so we should be cautious comparing this target against
+  // anything at this stage.
+  if (removed) {
+    nsCOMPtr<nsIEventTarget> target = observer->GetEventTarget();
+    if (target) {
+      MOZ_ASSERT(mObserversWithTargets > 0);
+      --mObserversWithTargets;
+
+      if (mObserversWithTargets == 0) {
+        MutexAutoLock lock(mMutex);
+        nsCOMPtr<nsIEventTarget> target(SystemGroup::EventTargetFor(TaskCategory::Other));
+        mEventTarget = WrapNotNull(target);
+      }
+    }
+
+    MOZ_ASSERT(mObserversWithTargets <= ObserverCount());
+  }
+
   // Observers can get confused if they don't get all the proper teardown
   // notifications. Part ways on good terms.
   if (removed && !aObserver->NotificationsDeferred()) {
     EmulateRequestFinished(aObserver);
   }
 
   // Make sure we don't give callbacks to an observer that isn't interested in
   // them any more.
--- a/image/ProgressTracker.h
+++ b/image/ProgressTracker.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 mozilla_image_ProgressTracker_h
 #define mozilla_image_ProgressTracker_h
 
 #include "CopyOnWrite.h"
+#include "mozilla/NotNull.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/WeakPtr.h"
 #include "nsDataHashtable.h"
 #include "nsCOMPtr.h"
 #include "nsTObserverArray.h"
 #include "nsThreadUtils.h"
 #include "nsRect.h"
@@ -108,28 +109,22 @@ private:
 class ProgressTracker : public mozilla::SupportsWeakPtr<ProgressTracker>
 {
   virtual ~ProgressTracker() { }
 
 public:
   MOZ_DECLARE_WEAKREFERENCE_TYPENAME(ProgressTracker)
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ProgressTracker)
 
-  ProgressTracker()
-    : mImageMutex("ProgressTracker::mImage")
-    , mImage(nullptr)
-    , mObservers(new ObserverTable)
-    , mProgress(NoProgress)
-    , mIsMultipart(false)
-  { }
+  ProgressTracker();
 
-  bool HasImage() const { MutexAutoLock lock(mImageMutex); return mImage; }
+  bool HasImage() const { MutexAutoLock lock(mMutex); return mImage; }
   already_AddRefed<Image> GetImage() const
   {
-    MutexAutoLock lock(mImageMutex);
+    MutexAutoLock lock(mMutex);
     RefPtr<Image> image = mImage;
     return image.forget();
   }
 
   // Get the current image status (as in imgIRequest).
   uint32_t GetImageStatus() const;
 
   // Get the current Progress.
@@ -187,16 +182,19 @@ public:
                           const nsIntRect& aInvalidRect = nsIntRect());
 
   // We manage a set of observers that are using an image and thus concerned
   // with its loading progress. Weak pointers.
   void AddObserver(IProgressObserver* aObserver);
   bool RemoveObserver(IProgressObserver* aObserver);
   uint32_t ObserverCount() const;
 
+  // Get the event target we should currently dispatch events to.
+  already_AddRefed<nsIEventTarget> GetEventTarget() const;
+
   // Resets our weak reference to our image. Image subclasses should call this
   // in their destructor.
   void ResetImage();
 
   // Tell this progress tracker that it is for a multipart image.
   void SetIsMultipart() { mIsMultipart = true; }
 
 private:
@@ -215,21 +213,39 @@ private:
   void EmulateRequestFinished(IProgressObserver* aObserver);
 
   // Main thread only because it deals with the observer service.
   void FireFailureNotification();
 
   // The runnable, if any, that we've scheduled to deliver async notifications.
   nsCOMPtr<nsIRunnable> mRunnable;
 
+  // mMutex protects access to mImage and mEventTarget.
+  mutable Mutex mMutex;
+
   // mImage is a weak ref; it should be set to null when the image goes out of
-  // scope. mImageMutex protects mImage.
-  mutable Mutex mImageMutex;
+  // scope.
   Image* mImage;
 
+  // mEventTarget is the current, best effort event target to dispatch
+  // notifications to from the decoder threads. It will change as observers are
+  // added and removed (see mObserversWithTargets).
+  NotNull<nsCOMPtr<nsIEventTarget>> mEventTarget;
+
+  // How many observers have been added that have an explicit event target.
+  // When the first observer is added with an explicit event target, we will
+  // default to that as long as all observers use the same target. If a new
+  // observer is added which has a different event target, we will switch to
+  // using the unlabeled main thread event target which is safe for all
+  // observers. If all observers with explicit event targets are removed, we
+  // will revert back to the initial event target (for SystemGroup). An
+  // observer without an explicit event target does not care what context it
+  // is dispatched in, and thus does not impact the state.
+  uint32_t mObserversWithTargets;
+
   // Hashtable of observers attached to the image. Each observer represents a
   // consumer using the image. Main thread only.
   CopyOnWrite<ObserverTable> mObservers;
 
   Progress mProgress;
 
   // Whether this is a progress tracker for a multipart image.
   bool mIsMultipart;
--- a/image/ScriptedNotificationObserver.cpp
+++ b/image/ScriptedNotificationObserver.cpp
@@ -2,16 +2,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/. */
 
 #include "ScriptedNotificationObserver.h"
 #include "imgIScriptedNotificationObserver.h"
 #include "nsCycleCollectionParticipant.h"
+#include "nsContentUtils.h"                     // for nsAutoScriptBlocker
 
 namespace mozilla {
 namespace image {
 
 NS_IMPL_CYCLE_COLLECTION(ScriptedNotificationObserver, mInner)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ScriptedNotificationObserver)
   NS_INTERFACE_MAP_ENTRY(imgINotificationObserver)
@@ -26,16 +27,23 @@ ScriptedNotificationObserver::ScriptedNo
 : mInner(aInner)
 { }
 
 NS_IMETHODIMP
 ScriptedNotificationObserver::Notify(imgIRequest* aRequest,
                                      int32_t aType,
                                      const nsIntRect* /*aUnused*/)
 {
+  // For now, we block (other) scripts from running to preserve the historical
+  // behavior from when ScriptedNotificationObserver::Notify was called as part
+  // of the observers list in nsImageLoadingContent::Notify. Now each
+  // ScriptedNotificationObserver has its own imgRequestProxy and thus gets
+  // Notify called directly by imagelib.
+  nsAutoScriptBlocker scriptBlocker;
+
   if (aType == imgINotificationObserver::SIZE_AVAILABLE) {
     return mInner->SizeAvailable(aRequest);
   }
   if (aType == imgINotificationObserver::FRAME_UPDATE) {
     return mInner->FrameUpdate(aRequest);
   }
   if (aType == imgINotificationObserver::FRAME_COMPLETE) {
     return mInner->FrameComplete(aRequest);
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -1050,16 +1050,17 @@ imgCacheQueue::const_iterator
 imgCacheQueue::end() const
 {
   return mQueue.end();
 }
 
 nsresult
 imgLoader::CreateNewProxyForRequest(imgRequest* aRequest,
                                     nsILoadGroup* aLoadGroup,
+                                    nsIDocument* aLoadingDocument,
                                     imgINotificationObserver* aObserver,
                                     nsLoadFlags aLoadFlags,
                                     imgRequestProxy** _retval)
 {
   LOG_SCOPE_WITH_PARAM(gImgLog, "imgLoader::CreateNewProxyForRequest",
                        "imgRequest", aRequest);
 
   /* XXX If we move decoding onto separate threads, we should save off the
@@ -1073,17 +1074,18 @@ imgLoader::CreateNewProxyForRequest(imgR
      |Init()| adds the request to the loadgroup.
    */
   proxyRequest->SetLoadFlags(aLoadFlags);
 
   RefPtr<ImageURL> uri;
   aRequest->GetURI(getter_AddRefs(uri));
 
   // init adds itself to imgRequest's list of observers
-  nsresult rv = proxyRequest->Init(aRequest, aLoadGroup, uri, aObserver);
+  nsresult rv = proxyRequest->Init(aRequest, aLoadGroup, aLoadingDocument,
+                                   uri, aObserver);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   proxyRequest.forget(_retval);
   return NS_OK;
 }
 
@@ -1640,33 +1642,34 @@ bool
 imgLoader::ValidateRequestWithNewChannel(imgRequest* request,
                                          nsIURI* aURI,
                                          nsIURI* aInitialDocumentURI,
                                          nsIURI* aReferrerURI,
                                          ReferrerPolicy aReferrerPolicy,
                                          nsILoadGroup* aLoadGroup,
                                          imgINotificationObserver* aObserver,
                                          nsISupports* aCX,
+                                         nsIDocument* aLoadingDocument,
                                          nsLoadFlags aLoadFlags,
                                          nsContentPolicyType aLoadPolicyType,
                                          imgRequestProxy** aProxyRequest,
                                          nsIPrincipal* aLoadingPrincipal,
                                          int32_t aCORSMode)
 {
   // now we need to insert a new channel request object inbetween the real
   // request and the proxy that basically delays loading the image until it
   // gets a 304 or figures out that this needs to be a new request
 
   nsresult rv;
 
   // If we're currently in the middle of validating this request, just hand
   // back a proxy to it; the required work will be done for us.
   if (request->GetValidator()) {
-    rv = CreateNewProxyForRequest(request, aLoadGroup, aObserver,
-                                  aLoadFlags, aProxyRequest);
+    rv = CreateNewProxyForRequest(request, aLoadGroup, aLoadingDocument,
+                                  aObserver, aLoadFlags, aProxyRequest);
     if (NS_FAILED(rv)) {
       return false;
     }
 
     if (*aProxyRequest) {
       imgRequestProxy* proxy = static_cast<imgRequestProxy*>(*aProxyRequest);
 
       // We will send notifications from imgCacheValidator::OnStartRequest().
@@ -1701,18 +1704,18 @@ imgLoader::ValidateRequestWithNewChannel
                        aLoadingPrincipal,
                        aCX,
                        mRespectPrivacy);
   if (NS_FAILED(rv)) {
     return false;
   }
 
   RefPtr<imgRequestProxy> req;
-  rv = CreateNewProxyForRequest(request, aLoadGroup, aObserver,
-                                aLoadFlags, getter_AddRefs(req));
+  rv = CreateNewProxyForRequest(request, aLoadGroup, aLoadingDocument,
+                                aObserver, aLoadFlags, getter_AddRefs(req));
   if (NS_FAILED(rv)) {
     return false;
   }
 
   // Make sure that OnStatus/OnProgress calls have the right request set...
   RefPtr<nsProgressNotificationProxy> progressproxy =
     new nsProgressNotificationProxy(newChannel, req);
   if (!progressproxy) {
@@ -1760,16 +1763,17 @@ bool
 imgLoader::ValidateEntry(imgCacheEntry* aEntry,
                          nsIURI* aURI,
                          nsIURI* aInitialDocumentURI,
                          nsIURI* aReferrerURI,
                          ReferrerPolicy aReferrerPolicy,
                          nsILoadGroup* aLoadGroup,
                          imgINotificationObserver* aObserver,
                          nsISupports* aCX,
+                         nsIDocument* aLoadingDocument,
                          nsLoadFlags aLoadFlags,
                          nsContentPolicyType aLoadPolicyType,
                          bool aCanMakeNewChannel,
                          imgRequestProxy** aProxyRequest,
                          nsIPrincipal* aLoadingPrincipal,
                          int32_t aCORSMode)
 {
   LOG_SCOPE(gImgLog, "imgLoader::ValidateEntry");
@@ -1880,17 +1884,18 @@ imgLoader::ValidateEntry(imgCacheEntry* 
 
   if (validateRequest && aCanMakeNewChannel) {
     LOG_SCOPE(gImgLog,
               "imgLoader::ValidateRequest |cache hit| must validate");
 
     return ValidateRequestWithNewChannel(request, aURI, aInitialDocumentURI,
                                          aReferrerURI, aReferrerPolicy,
                                          aLoadGroup, aObserver,
-                                         aCX, aLoadFlags, aLoadPolicyType,
+                                         aCX, aLoadingDocument,
+                                         aLoadFlags, aLoadPolicyType,
                                          aProxyRequest, aLoadingPrincipal,
                                          aCORSMode);
   }
 
   return !validateRequest;
 }
 
 bool
@@ -2164,18 +2169,18 @@ imgLoader::LoadImage(nsIURI* aURI,
   }
   ImageCacheKey key(aURI, attrs, aLoadingDocument, rv);
   NS_ENSURE_SUCCESS(rv, rv);
   imgCacheTable& cache = GetCache(key);
 
   if (cache.Get(key, getter_AddRefs(entry)) && entry) {
     if (ValidateEntry(entry, aURI, aInitialDocumentURI, aReferrerURI,
                       aReferrerPolicy, aLoadGroup, aObserver, aLoadingDocument,
-                      requestFlags, aContentPolicyType, true, _retval,
-                      aLoadingPrincipal, corsmode)) {
+                      aLoadingDocument, requestFlags, aContentPolicyType, true,
+                      _retval, aLoadingPrincipal, corsmode)) {
       request = entry->GetRequest();
 
       // If this entry has no proxies, its request has no reference to the
       // entry.
       if (entry->HasNoProxies()) {
         LOG_FUNC_WITH_PARAM(gImgLog,
           "imgLoader::LoadImage() adding proxyless entry", "uri", key.Spec());
         MOZ_ASSERT(!request->HasCacheEntry(),
@@ -2290,18 +2295,18 @@ imgLoader::LoadImage(nsIURI* aURI,
     //
     // Note, however, that this doesn't guarantee the behaviour we want (one
     // URL maps to the same image on a page) if we load the same image in a
     // different tab (see bug 528003), because its load id will get re-set, and
     // that'll cause us to validate over the network.
     request->SetLoadId(aLoadingDocument);
 
     LOG_MSG(gImgLog, "imgLoader::LoadImage", "creating proxy request.");
-    rv = CreateNewProxyForRequest(request, aLoadGroup, aObserver,
-                                  requestFlags, _retval);
+    rv = CreateNewProxyForRequest(request, aLoadGroup, aLoadingDocument,
+                                  aObserver, requestFlags, _retval);
     if (NS_FAILED(rv)) {
       return rv;
     }
 
     imgRequestProxy* proxy = *_retval;
 
     // Make sure that OnStatus/OnProgress calls have the right request set, if
     // we did create a channel here.
@@ -2412,17 +2417,17 @@ imgLoader::LoadImageWithChannel(nsIChann
       nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
       // if there is a loadInfo, use the right contentType, otherwise
       // default to the internal image type
       nsContentPolicyType policyType = loadInfo
         ? loadInfo->InternalContentPolicyType()
         : nsIContentPolicy::TYPE_INTERNAL_IMAGE;
 
       if (ValidateEntry(entry, uri, nullptr, nullptr, RP_Unset,
-                        nullptr, aObserver, aCX, requestFlags,
+                        nullptr, aObserver, aCX, doc, requestFlags,
                         policyType, false, nullptr,
                         nullptr, imgIRequest::CORS_NONE)) {
         request = entry->GetRequest();
       } else {
         nsCOMPtr<nsICacheInfoChannel> cacheChan(do_QueryInterface(channel));
         bool bUseCacheCopy;
 
         if (cacheChan) {
@@ -2467,17 +2472,17 @@ imgLoader::LoadImageWithChannel(nsIChann
   if (request) {
     // we have this in our cache already.. cancel the current (document) load
 
     // this should fire an OnStopRequest
     channel->Cancel(NS_ERROR_PARSED_DATA_CACHED);
 
     *listener = nullptr; // give them back a null nsIStreamListener
 
-    rv = CreateNewProxyForRequest(request, loadGroup, aObserver,
+    rv = CreateNewProxyForRequest(request, loadGroup, doc, aObserver,
                                   requestFlags, _retval);
     static_cast<imgRequestProxy*>(*_retval)->NotifyListener();
   } else {
     // We use originalURI here to fulfil the imgIRequest contract on GetURI.
     nsCOMPtr<nsIURI> originalURI;
     channel->GetOriginalURI(getter_AddRefs(originalURI));
 
     // XXX(seth): We should be able to just use |key| here, except that |key| is
@@ -2510,17 +2515,17 @@ imgLoader::LoadImageWithChannel(nsIChann
 
     RefPtr<ProxyListener> pl =
       new ProxyListener(static_cast<nsIStreamListener*>(request.get()));
     pl.forget(listener);
 
     // Try to add the new request into the cache.
     PutIntoCache(originalURIKey, entry);
 
-    rv = CreateNewProxyForRequest(request, loadGroup, aObserver,
+    rv = CreateNewProxyForRequest(request, loadGroup, doc, aObserver,
                                   requestFlags, _retval);
 
     // Explicitly don't notify our proxy, because we're loading off the
     // network, and necko (or things called from necko, such as
     // imgCacheValidator) are going to call our notifications asynchronously,
     // and we can't make it further asynchronous because observers might rely
     // on imagelib completing its work between the channel's OnStartRequest and
     // OnStopRequest.
--- a/image/imgLoader.h
+++ b/image/imgLoader.h
@@ -393,37 +393,41 @@ private: // methods
 
   static already_AddRefed<imgLoader> CreateImageLoader();
 
   bool ValidateEntry(imgCacheEntry* aEntry, nsIURI* aKey,
                      nsIURI* aInitialDocumentURI, nsIURI* aReferrerURI,
                      ReferrerPolicy aReferrerPolicy,
                      nsILoadGroup* aLoadGroup,
                      imgINotificationObserver* aObserver, nsISupports* aCX,
+                     nsIDocument* aLoadingDocument,
                      nsLoadFlags aLoadFlags,
                      nsContentPolicyType aContentPolicyType,
                      bool aCanMakeNewChannel,