Bug 1331944 - Part 5. Integrate SharedSurfacesParent with the WebRender texture cache. r=jrmuizel
authorAndrew Osmond <aosmond@mozilla.com>
Mon, 30 Oct 2017 13:10:29 -0400
changeset 389148 3a29cc4edf473bf5da434f8e7f0c5af72d80aef8
parent 389147 12ac8625bf4ca24334ef7cdd68a95d92239a159c
child 389149 3741bc7ff417fc5e749e40b2baae51857eb8cf9d
push id32778
push userarchaeopteryx@coole-files.de
push dateMon, 30 Oct 2017 22:52:59 +0000
treeherdermozilla-central@083a9c84fbd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1331944
milestone58.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 1331944 - Part 5. Integrate SharedSurfacesParent with the WebRender texture cache. r=jrmuizel
gfx/layers/ipc/SharedSurfacesParent.cpp
--- a/gfx/layers/ipc/SharedSurfacesParent.cpp
+++ b/gfx/layers/ipc/SharedSurfacesParent.cpp
@@ -2,16 +2,18 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * 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 "SharedSurfacesParent.h"
 #include "mozilla/layers/SourceSurfaceSharedData.h"
 #include "mozilla/layers/CompositorThread.h"
+#include "mozilla/webrender/RenderSharedSurfaceTextureHost.h"
+#include "mozilla/webrender/RenderThread.h"
 
 namespace mozilla {
 namespace layers {
 
 using namespace mozilla::gfx;
 
 StaticAutoPtr<SharedSurfacesParent> SharedSurfacesParent::sInstance;
 
@@ -100,16 +102,21 @@ SharedSurfacesParent::AddSameProcess(con
   RefPtr<Runnable> task = NS_NewRunnableFunction(
     "layers::SharedSurfacesParent::AddSameProcess",
     [surface, id]() -> void {
       if (!sInstance) {
         return;
       }
 
       MOZ_ASSERT(!sInstance->mSurfaces.Contains(id));
+
+      RefPtr<wr::RenderSharedSurfaceTextureHost> texture =
+        new wr::RenderSharedSurfaceTextureHost(surface);
+      wr::RenderThread::Get()->RegisterExternalImage(id, texture.forget());
+
       sInstance->mSurfaces.Put(id, surface);
     });
 
   CompositorThreadHolder::Loop()->PostTask(task.forget());
 }
 
 /* static */ void
 SharedSurfacesParent::RemoveSameProcess(const wr::ExternalImageId& aId)
@@ -133,16 +140,17 @@ SharedSurfacesParent::DestroyProcess(bas
   if (!sInstance) {
     return;
   }
 
   // Note that the destruction of a parent may not be cheap if it still has a
   // lot of surfaces still bound that require unmapping.
   for (auto i = sInstance->mSurfaces.Iter(); !i.Done(); i.Next()) {
     if (i.Data()->GetCreatorPid() == aPid) {
+      wr::RenderThread::Get()->UnregisterExternalImage(i.Key());
       i.Remove();
     }
   }
 }
 
 /* static */ void
 SharedSurfacesParent::Add(const wr::ExternalImageId& aId,
                           const SurfaceDescriptorShared& aDesc,
@@ -160,16 +168,21 @@ SharedSurfacesParent::Add(const wr::Exte
   if (NS_WARN_IF(!surface->Init(aDesc.size(), aDesc.stride(),
                                 aDesc.format(), aDesc.handle(),
                                 aPid))) {
     return;
   }
 
   uint64_t id = wr::AsUint64(aId);
   MOZ_ASSERT(!sInstance->mSurfaces.Contains(id));
+
+  RefPtr<wr::RenderSharedSurfaceTextureHost> texture =
+    new wr::RenderSharedSurfaceTextureHost(surface);
+  wr::RenderThread::Get()->RegisterExternalImage(id, texture.forget());
+
   sInstance->mSurfaces.Put(id, surface.forget());
 }
 
 /* static */ void
 SharedSurfacesParent::Remove(const wr::ExternalImageId& aId)
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
   DebugOnly<bool> rv = Release(aId);