Bug 1516011 - Part 1. Ensure wrapped shared surfaces are retained for blob rasterization. r=jrmuizel
☠☠ backed out by 6b946ad790d0 ☠ ☠
authorAndrew Osmond <aosmond@mozilla.com>
Thu, 10 Jan 2019 07:41:18 -0500
changeset 453613 c74c81fe8dcb
parent 453612 0026b863c437
child 453614 3c5fcd8a2f4a
push id35361
push usernbeleuzu@mozilla.com
push dateSat, 12 Jan 2019 09:41:19 +0000
treeherdermozilla-central@a44934afe25e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1516011
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1516011 - Part 1. Ensure wrapped shared surfaces are retained for blob rasterization. r=jrmuizel References to shared surfaces are already kept alive for the blob in the content process, and it also ensures an image key is created to ensure any release of the surface is delayed until the next epoch. Wrapped shared surfaces (when used in an animation which is recycling its surfaces) did not get an image key created which this patch corrects. Differential Revision: https://phabricator.services.mozilla.com/D16191
gfx/layers/ipc/SharedSurfacesChild.cpp
gfx/layers/ipc/SharedSurfacesChild.h
gfx/layers/wr/WebRenderCommandBuilder.cpp
--- a/gfx/layers/ipc/SharedSurfacesChild.cpp
+++ b/gfx/layers/ipc/SharedSurfacesChild.cpp
@@ -304,16 +304,31 @@ SharedSurfacesChild::AsSourceSurfaceShar
     MOZ_ASSERT(data);
     aKey = data->UpdateKey(aManager, aResources, dirtyRect);
   }
 
   return rv;
 }
 
 /* static */ nsresult SharedSurfacesChild::Share(
+    SourceSurface* aSurface, RenderRootStateManager* aManager,
+    wr::IpcResourceUpdateQueue& aResources, wr::ImageKey& aKey) {
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aSurface);
+  MOZ_ASSERT(aManager);
+
+  auto sharedSurface = AsSourceSurfaceSharedData(aSurface);
+  if (!sharedSurface) {
+    return NS_ERROR_NOT_IMPLEMENTED;
+  }
+
+  return Share(sharedSurface, aManager, aResources, aKey);
+}
+
+/* static */ nsresult SharedSurfacesChild::Share(
     ImageContainer* aContainer, RenderRootStateManager* aManager,
     wr::IpcResourceUpdateQueue& aResources, wr::ImageKey& aKey) {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aContainer);
   MOZ_ASSERT(aManager);
 
   if (aContainer->IsAsync()) {
     return NS_ERROR_NOT_IMPLEMENTED;
--- a/gfx/layers/ipc/SharedSurfacesChild.h
+++ b/gfx/layers/ipc/SharedSurfacesChild.h
@@ -67,16 +67,26 @@ class SharedSurfacesChild final {
    * This must be called from the main thread.
    */
   static nsresult Share(gfx::SourceSurfaceSharedData* aSurface,
                         RenderRootStateManager* aManager,
                         wr::IpcResourceUpdateQueue& aResources,
                         wr::ImageKey& aKey);
 
   /**
+   * Request that the surface be mapped into the compositor thread's memory
+   * space, and a valid ImageKey be generated for it for use with WebRender.
+   * This must be called from the main thread.
+   */
+  static nsresult Share(gfx::SourceSurface* aSurface,
+                        RenderRootStateManager* aManager,
+                        wr::IpcResourceUpdateQueue& aResources,
+                        wr::ImageKey& aKey);
+
+  /**
    * Request that the first surface in the image container's current images be
    * mapped into the compositor thread's memory space, and a valid ImageKey be
    * generated for it for use with WebRender. If a different method should be
    * used to share the image data for this particular container, it will return
    * NS_ERROR_NOT_IMPLEMENTED. This must be called from the main thread.
    */
   static nsresult Share(ImageContainer* aContainer,
                         RenderRootStateManager* aManager,
--- a/gfx/layers/wr/WebRenderCommandBuilder.cpp
+++ b/gfx/layers/wr/WebRenderCommandBuilder.cpp
@@ -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/. */
 
 #include "WebRenderCommandBuilder.h"
 
 #include "BasicLayers.h"
 #include "mozilla/AutoRestore.h"
+#include "mozilla/DebugOnly.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/Logging.h"
 #include "mozilla/gfx/Types.h"
 #include "mozilla/layers/ClipManager.h"
 #include "mozilla/layers/ImageClient.h"
 #include "mozilla/layers/RenderRootStateManager.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
 #include "mozilla/layers/WebRenderLayerManager.h"
@@ -179,28 +180,24 @@ static void DestroyBlobGroupDataProperty
 
 static void TakeExternalSurfaces(
     WebRenderDrawEventRecorder* aRecorder,
     std::vector<RefPtr<SourceSurface>>& aExternalSurfaces,
     RenderRootStateManager* aManager, wr::IpcResourceUpdateQueue& aResources) {
   aRecorder->TakeExternalSurfaces(aExternalSurfaces);
 
   for (auto& surface : aExternalSurfaces) {
-    if (surface->GetType() != SurfaceType::DATA_SHARED) {
-      MOZ_ASSERT_UNREACHABLE("External surface that is not a shared surface!");
-      continue;
-    }
-
     // While we don't use the image key with the surface, because the blob image
     // renderer doesn't have easy access to the resource set, we still want to
     // ensure one is generated. That will ensure the surface remains alive until
     // at least the last epoch which the blob image could be used in.
     wr::ImageKey key;
-    auto sharedSurface = static_cast<SourceSurfaceSharedData*>(surface.get());
-    SharedSurfacesChild::Share(sharedSurface, aManager, aResources, key);
+    DebugOnly<nsresult> rv =
+        SharedSurfacesChild::Share(surface, aManager, aResources, key);
+    MOZ_ASSERT(rv != NS_ERROR_NOT_IMPLEMENTED);
   }
 }
 
 struct DIGroup;
 struct Grouper {
   explicit Grouper(ClipManager& aClipManager)
       : mAppUnitsPerDevPixel(0),
         mDisplayListBuilder(nullptr),