Backed out changeset 7e1da430d9f9::7c56a10468d7 (bug 1331944) for bustage on Android at gfx/layers/ipc/SharedSurfacesParent.cpp r=backout on a CLOSED TREE
authorCoroiu Cristina <ccoroiu@mozilla.com>
Mon, 30 Oct 2017 15:52:07 +0200
changeset 439869 719f1c2189d28fa84d6010d21883cc56df09a9d9
parent 439868 e6028f5b67bf02fed17fc4b5d371b5f8333ae06f
child 439870 7c264d9bf22a0c2b42aae52ce548961a6009b02f
push id8114
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 16:33:21 +0000
treeherdermozilla-beta@73e0d89a540f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1331944
milestone58.0a1
backs out7e1da430d9f9323ef4fd0690459fd87c8d1ba0ef
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
Backed out changeset 7e1da430d9f9::7c56a10468d7 (bug 1331944) for bustage on Android at gfx/layers/ipc/SharedSurfacesParent.cpp r=backout on a CLOSED TREE Backed out changeset 7c56a10468d7 (bug 1331944) Backed out changeset b77eb1c48b73 (bug 1331944) Backed out changeset 50b1fcf13fba (bug 1331944) Backed out changeset 56e6ab347bae (bug 1331944) Backed out changeset 5bdfda0b0b3a (bug 1331944) Backed out changeset 40ec55507394 (bug 1331944) Backed out changeset 83cc1f67e9f7 (bug 1331944) Backed out changeset 7e1da430d9f9 (bug 1331944)
gfx/layers/SourceSurfaceSharedData.cpp
gfx/layers/SourceSurfaceSharedData.h
gfx/layers/ipc/CompositorManagerChild.h
gfx/layers/ipc/CompositorManagerParent.cpp
gfx/layers/ipc/CompositorManagerParent.h
gfx/layers/ipc/CompositorThread.cpp
gfx/layers/ipc/LayersSurfaces.ipdlh
gfx/layers/ipc/PCompositorManager.ipdl
gfx/layers/ipc/SharedSurfacesChild.cpp
gfx/layers/ipc/SharedSurfacesChild.h
gfx/layers/ipc/SharedSurfacesParent.cpp
gfx/layers/ipc/SharedSurfacesParent.h
gfx/layers/moz.build
gfx/layers/wr/WebRenderBridgeParent.cpp
gfx/layers/wr/WebRenderUserData.cpp
gfx/layers/wr/WebRenderUserData.h
gfx/webrender_bindings/RenderBufferTextureHost.cpp
gfx/webrender_bindings/RenderBufferTextureHost.h
gfx/webrender_bindings/RenderD3D11TextureHostOGL.cpp
gfx/webrender_bindings/RenderD3D11TextureHostOGL.h
gfx/webrender_bindings/RenderMacIOSurfaceTextureHostOGL.cpp
gfx/webrender_bindings/RenderMacIOSurfaceTextureHostOGL.h
gfx/webrender_bindings/RenderSharedSurfaceTextureHost.cpp
gfx/webrender_bindings/RenderSharedSurfaceTextureHost.h
gfx/webrender_bindings/RenderTextureHost.h
gfx/webrender_bindings/RenderTextureHostOGL.h
gfx/webrender_bindings/RendererOGL.cpp
gfx/webrender_bindings/moz.build
--- a/gfx/layers/SourceSurfaceSharedData.cpp
+++ b/gfx/layers/SourceSurfaceSharedData.cpp
@@ -7,53 +7,16 @@
 
 #include "mozilla/Likely.h"
 #include "mozilla/Types.h" // for decltype
 
 namespace mozilla {
 namespace gfx {
 
 bool
-SourceSurfaceSharedDataWrapper::Init(const IntSize& aSize,
-                                     int32_t aStride,
-                                     SurfaceFormat aFormat,
-                                     const SharedMemoryBasic::Handle& aHandle,
-                                     base::ProcessId aCreatorPid)
-{
-  MOZ_ASSERT(!mBuf);
-  mSize = aSize;
-  mStride = aStride;
-  mFormat = aFormat;
-  mCreatorPid = aCreatorPid;
-
-  size_t len = GetAlignedDataLength();
-  mBuf = new SharedMemoryBasic();
-  if (NS_WARN_IF(!mBuf->SetHandle(aHandle, ipc::SharedMemory::RightsReadOnly)) ||
-      NS_WARN_IF(!mBuf->Map(len))) {
-    mBuf = nullptr;
-    return false;
-  }
-
-  mBuf->CloseHandle();
-  return true;
-}
-
-void
-SourceSurfaceSharedDataWrapper::Init(SourceSurfaceSharedData* aSurface)
-{
-  MOZ_ASSERT(!mBuf);
-  MOZ_ASSERT(aSurface);
-  mSize = aSurface->mSize;
-  mStride = aSurface->mStride;
-  mFormat = aSurface->mFormat;
-  mCreatorPid = base::GetCurrentProcId();
-  mBuf = aSurface->mBuf;
-}
-
-bool
 SourceSurfaceSharedData::Init(const IntSize &aSize,
                               int32_t aStride,
                               SurfaceFormat aFormat)
 {
   mSize = aSize;
   mStride = aStride;
   mFormat = aFormat;
 
@@ -99,17 +62,16 @@ SourceSurfaceSharedData::GetDataInternal
   return static_cast<uint8_t*>(mBuf->memory());
 }
 
 nsresult
 SourceSurfaceSharedData::ShareToProcess(base::ProcessId aPid,
                                         SharedMemoryBasic::Handle& aHandle)
 {
   MutexAutoLock lock(mMutex);
-  MOZ_ASSERT(mHandleCount > 0);
 
   if (mClosed) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   bool shared = mBuf->ShareToProcess(aPid, &aHandle);
   if (MOZ_UNLIKELY(!shared)) {
     return NS_ERROR_FAILURE;
@@ -119,33 +81,29 @@ SourceSurfaceSharedData::ShareToProcess(
 }
 
 void
 SourceSurfaceSharedData::CloseHandleInternal()
 {
   mMutex.AssertCurrentThreadOwns();
 
   if (mClosed) {
-    MOZ_ASSERT(mHandleCount == 0);
-    MOZ_ASSERT(mFinalized);
-    MOZ_ASSERT(mShared);
     return;
   }
 
   if (mFinalized && mShared) {
     mBuf->CloseHandle();
     mClosed = true;
   }
 }
 
 bool
 SourceSurfaceSharedData::ReallocHandle()
 {
   MutexAutoLock lock(mMutex);
-  MOZ_ASSERT(mHandleCount > 0);
   MOZ_ASSERT(mClosed);
   MOZ_ASSERT(mFinalized);
 
   size_t len = GetAlignedDataLength();
   RefPtr<SharedMemoryBasic> buf = new SharedMemoryBasic();
   if (NS_WARN_IF(!buf->Create(len)) ||
       NS_WARN_IF(!buf->Map(len))) {
     return false;
--- a/gfx/layers/SourceSurfaceSharedData.h
+++ b/gfx/layers/SourceSurfaceSharedData.h
@@ -8,123 +8,39 @@
 
 #include "mozilla/gfx/2D.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/ipc/SharedMemoryBasic.h"
 
 namespace mozilla {
 namespace gfx {
 
-class SourceSurfaceSharedData;
-
-class SourceSurfaceSharedDataWrapper final : public DataSourceSurface
-{
-  typedef mozilla::ipc::SharedMemoryBasic SharedMemoryBasic;
-
-public:
-  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceSharedDataWrapper, override)
-
-  SourceSurfaceSharedDataWrapper()
-    : mStride(0)
-    , mFormat(SurfaceFormat::UNKNOWN)
-  { }
-
-  bool Init(const IntSize& aSize,
-            int32_t aStride,
-            SurfaceFormat aFormat,
-            const SharedMemoryBasic::Handle& aHandle,
-            base::ProcessId aCreatorPid);
-
-  void Init(SourceSurfaceSharedData *aSurface);
-
-  base::ProcessId GetCreatorPid() const
-  {
-    return mCreatorPid;
-  }
-
-  int32_t Stride() override { return mStride; }
-
-  SurfaceType GetType() const override { return SurfaceType::DATA; }
-  IntSize GetSize() const override { return mSize; }
-  SurfaceFormat GetFormat() const override { return mFormat; }
-
-  uint8_t* GetData() override
-  {
-    return static_cast<uint8_t*>(mBuf->memory());
-  }
-
-  bool OnHeap() const override
-  {
-    return false;
-  }
-
-  bool Map(MapType, MappedSurface *aMappedSurface) override
-  {
-    aMappedSurface->mData = GetData();
-    aMappedSurface->mStride = mStride;
-    return true;
-  }
-
-  void Unmap() override
-  { }
-
-  bool AddConsumer()
-  {
-    return ++mConsumers == 1;
-  }
-
-  bool RemoveConsumer()
-  {
-    MOZ_ASSERT(mConsumers > 0);
-    return --mConsumers == 0;
-  }
-
-private:
-  size_t GetDataLength() const
-  {
-    return static_cast<size_t>(mStride) * mSize.height;
-  }
-
-  size_t GetAlignedDataLength() const
-  {
-    return mozilla::ipc::SharedMemory::PageAlignedSize(GetDataLength());
-  }
-
-  int32_t mStride;
-  uint32_t mConsumers;
-  IntSize mSize;
-  RefPtr<SharedMemoryBasic> mBuf;
-  SurfaceFormat mFormat;
-  base::ProcessId mCreatorPid;
-};
-
 /**
  * This class is used to wrap shared (as in process) data buffers used by a
  * source surface.
  */
 class SourceSurfaceSharedData final : public DataSourceSurface
 {
   typedef mozilla::ipc::SharedMemoryBasic SharedMemoryBasic;
 
 public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceSharedData, override)
 
   SourceSurfaceSharedData()
     : mMutex("SourceSurfaceSharedData")
     , mStride(0)
     , mMapCount(0)
-    , mHandleCount(0)
     , mFormat(SurfaceFormat::UNKNOWN)
     , mClosed(false)
     , mFinalized(false)
     , mShared(false)
   {
   }
 
-  bool Init(const IntSize& aSize,
+  bool Init(const IntSize &aSize,
             int32_t aStride,
             SurfaceFormat aFormat);
 
   uint8_t* GetData() override
   {
     MutexAutoLock lock(mMutex);
     return GetDataInternal();
   }
@@ -212,75 +128,27 @@ public:
    * Allocate a new shared memory buffer so that we can get a new handle for
    * sharing to new processes. ShareToProcess must have failed with
    * NS_ERROR_NOT_AVAILABLE in order for this to be safe to call. Returns true
    * if the operation succeeds. If it fails, there is no state change.
    */
   bool ReallocHandle();
 
   /**
-   * Signals we have finished writing to the buffer and it may be marked as
+   * Indicates we have finished writing to the buffer and it may be marked as
    * read only. May release the handle if possible (see CloseHandleInternal).
    */
   void Finalize();
 
-  /**
-   * Indicates whether or not the buffer can change. If this returns true, it is
-   * guaranteed to continue to do so for the remainder of the surface's life.
-   */
-  bool IsFinalized() const
-  {
-    MutexAutoLock lock(mMutex);
-    return mFinalized;
-  }
-
-  /**
-   * While a HandleLock exists for the given surface, the shared memory handle
-   * cannot be released.
-   */
-  class MOZ_STACK_CLASS HandleLock final {
-  public:
-    explicit HandleLock(SourceSurfaceSharedData* aSurface)
-      : mSurface(aSurface)
-    {
-      mSurface->LockHandle();
-    }
-
-    ~HandleLock()
-    {
-      mSurface->UnlockHandle();
-    }
-
-  private:
-    RefPtr<SourceSurfaceSharedData> mSurface;
-  };
-
 private:
-  friend class SourceSurfaceSharedDataWrapper;
-
   ~SourceSurfaceSharedData() override
   {
     MOZ_ASSERT(mMapCount == 0);
   }
 
-  void LockHandle()
-  {
-    MutexAutoLock lock(mMutex);
-    ++mHandleCount;
-  }
-
-  void UnlockHandle()
-  {
-    MutexAutoLock lock(mMutex);
-    MOZ_ASSERT(mHandleCount > 0);
-    --mHandleCount;
-    mShared = true;
-    CloseHandleInternal();
-  }
-
   uint8_t* GetDataInternal() const;
 
   size_t GetDataLength() const
   {
     return static_cast<size_t>(mStride) * mSize.height;
   }
 
   size_t GetAlignedDataLength() const
@@ -292,17 +160,16 @@ private:
    * Attempt to close the handle. Only if the buffer has been both finalized
    * and we have completed sharing will it be released.
    */
   void CloseHandleInternal();
 
   mutable Mutex mMutex;
   int32_t mStride;
   int32_t mMapCount;
-  int32_t mHandleCount;
   IntSize mSize;
   RefPtr<SharedMemoryBasic> mBuf;
   RefPtr<SharedMemoryBasic> mOldBuf;
   SurfaceFormat mFormat;
   bool mClosed : 1;
   bool mFinalized : 1;
   bool mShared : 1;
 };
--- a/gfx/layers/ipc/CompositorManagerChild.h
+++ b/gfx/layers/ipc/CompositorManagerChild.h
@@ -43,52 +43,26 @@ public:
                                const CompositorOptions& aOptions,
                                bool aUseExternalSurfaceSize,
                                const gfx::IntSize& aSurfaceSize);
 
   static already_AddRefed<CompositorBridgeChild>
   CreateSameProcessWidgetCompositorBridge(LayerManager* aLayerManager,
                                           uint32_t aNamespace);
 
-  static CompositorManagerChild* GetInstance()
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-    return sInstance;
-  }
-
-  bool CanSend() const
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-    return mCanSend;
-  }
-
   uint32_t GetNextResourceId()
   {
-    MOZ_ASSERT(NS_IsMainThread());
     return ++mResourceId;
   }
 
   uint32_t GetNamespace() const
   {
     return mNamespace;
   }
 
-  bool OwnsExternalImageId(const wr::ExternalImageId& aId) const
-  {
-    return mNamespace == static_cast<uint32_t>(wr::AsUint64(aId) >> 32);
-  }
-
-  wr::ExternalImageId GetNextExternalImageId()
-  {
-    uint64_t id = GetNextResourceId();
-    MOZ_RELEASE_ASSERT(id != 0);
-    id |= (static_cast<uint64_t>(mNamespace) << 32);
-    return wr::ToExternalImageId(id);
-  }
-
   void ActorDestroy(ActorDestroyReason aReason) override;
 
   void HandleFatalError(const char* aName, const char* aMsg) const override;
 
   void ProcessingError(Result aCode, const char* aReason) override;
 
   PCompositorBridgeChild* AllocPCompositorBridgeChild(const CompositorBridgeOptions& aOptions) override;
 
@@ -106,16 +80,22 @@ private:
   CompositorManagerChild(Endpoint<PCompositorManagerChild>&& aEndpoint,
                          uint64_t aProcessToken,
                          uint32_t aNamespace);
 
   ~CompositorManagerChild() override
   {
   }
 
+  bool CanSend() const
+  {
+    MOZ_ASSERT(NS_IsMainThread());
+    return mCanSend;
+  }
+
   void DeallocPCompositorManagerChild() override;
 
   already_AddRefed<nsIEventTarget>
   GetSpecificMessageEventTarget(const Message& aMsg) override;
 
   void SetReplyTimeout();
 
   uint64_t mProcessToken;
--- a/gfx/layers/ipc/CompositorManagerParent.cpp
+++ b/gfx/layers/ipc/CompositorManagerParent.cpp
@@ -4,17 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/layers/CompositorManagerParent.h"
 #include "mozilla/gfx/GPUParent.h"
 #include "mozilla/layers/CompositorBridgeParent.h"
 #include "mozilla/layers/CrossProcessCompositorBridgeParent.h"
 #include "mozilla/layers/CompositorThread.h"
-#include "mozilla/layers/SharedSurfacesParent.h"
 #include "nsAutoPtr.h"
 #include "VsyncSource.h"
 
 namespace mozilla {
 namespace layers {
 
 StaticRefPtr<CompositorManagerParent> CompositorManagerParent::sInstance;
 StaticMutex CompositorManagerParent::sMutex;
@@ -146,18 +145,16 @@ CompositorManagerParent::BindComplete()
   }
   sActiveActors->AppendElement(this);
 #endif
 }
 
 void
 CompositorManagerParent::ActorDestroy(ActorDestroyReason aReason)
 {
-  SharedSurfacesParent::DestroyProcess(OtherPid());
-
   StaticMutexAutoLock lock(sMutex);
   if (sInstance == this) {
     sInstance = nullptr;
   }
 }
 
 void
 CompositorManagerParent::DeallocPCompositorManagerParent()
@@ -271,25 +268,10 @@ CompositorManagerParent::AllocPComposito
 
 bool
 CompositorManagerParent::DeallocPCompositorBridgeParent(PCompositorBridgeParent* aActor)
 {
   static_cast<CompositorBridgeParentBase*>(aActor)->Release();
   return true;
 }
 
-mozilla::ipc::IPCResult
-CompositorManagerParent::RecvAddSharedSurface(const wr::ExternalImageId& aId,
-                                              const SurfaceDescriptorShared& aDesc)
-{
-  SharedSurfacesParent::Add(aId, aDesc, OtherPid());
-  return IPC_OK();
-}
-
-mozilla::ipc::IPCResult
-CompositorManagerParent::RecvRemoveSharedSurface(const wr::ExternalImageId& aId)
-{
-  SharedSurfacesParent::Remove(aId);
-  return IPC_OK();
-}
-
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/ipc/CompositorManagerParent.h
+++ b/gfx/layers/ipc/CompositorManagerParent.h
@@ -34,20 +34,16 @@ public:
   static void Shutdown();
 
   static already_AddRefed<CompositorBridgeParent>
   CreateSameProcessWidgetCompositorBridge(CSSToLayoutDeviceScale aScale,
                                           const CompositorOptions& aOptions,
                                           bool aUseExternalSurfaceSize,
                                           const gfx::IntSize& aSurfaceSize);
 
-  mozilla::ipc::IPCResult RecvAddSharedSurface(const wr::ExternalImageId& aId,
-                                               const SurfaceDescriptorShared& aDesc) override;
-  mozilla::ipc::IPCResult RecvRemoveSharedSurface(const wr::ExternalImageId& aId) override;
-
   void BindComplete();
   void ActorDestroy(ActorDestroyReason aReason) override;
 
   bool DeallocPCompositorBridgeParent(PCompositorBridgeParent* aActor) override;
   PCompositorBridgeParent* AllocPCompositorBridgeParent(const CompositorBridgeOptions& aOpt) override;
 
 private:
   static StaticRefPtr<CompositorManagerParent> sInstance;
--- a/gfx/layers/ipc/CompositorThread.cpp
+++ b/gfx/layers/ipc/CompositorThread.cpp
@@ -3,17 +3,16 @@
 /* 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 "CompositorThread.h"
 #include "MainThreadUtils.h"
 #include "nsThreadUtils.h"
 #include "CompositorBridgeParent.h"
 #include "mozilla/layers/ImageBridgeParent.h"
-#include "mozilla/layers/SharedSurfacesParent.h"
 #include "mozilla/media/MediaSystemResourceService.h"
 #ifdef MOZ_CRASHREPORTER
 #include "nsExceptionHandler.h"     // for CrashReporter
 #endif
 
 namespace mozilla {
 
 namespace gfx {
@@ -94,17 +93,16 @@ CompositorThreadHolder::~CompositorThrea
 /* static */ void
 CompositorThreadHolder::DestroyCompositorThread(base::Thread* aCompositorThread)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   MOZ_ASSERT(!sCompositorThreadHolder, "We shouldn't be destroying the compositor thread yet.");
 
   CompositorBridgeParent::Shutdown();
-  SharedSurfacesParent::Shutdown();
   delete aCompositorThread;
   sFinishedCompositorShutDown = true;
 }
 
 /* static */ base::Thread*
 CompositorThreadHolder::CreateCompositorThread()
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -129,17 +127,16 @@ CompositorThreadHolder::CreateCompositor
   options.message_loop_type = MessageLoop::TYPE_UI;
 #endif
 
   if (!compositorThread->StartWithOptions(options)) {
     delete compositorThread;
     return nullptr;
   }
 
-  SharedSurfacesParent::Initialize();
   CompositorBridgeParent::Setup();
   ImageBridgeParent::Setup();
 
   return compositorThread;
 }
 
 void
 CompositorThreadHolder::Start()
--- a/gfx/layers/ipc/LayersSurfaces.ipdlh
+++ b/gfx/layers/ipc/LayersSurfaces.ipdlh
@@ -7,17 +7,16 @@ using nsIntRegion from "nsRegion.h";
 using struct mozilla::layers::SurfaceDescriptorX11 from "gfxipc/ShadowLayerUtils.h";
 using mozilla::StereoMode from "ImageTypes.h";
 using mozilla::YUVColorSpace from "ImageTypes.h";
 using struct mozilla::null_t from "ipc/IPCMessageUtils.h";
 using mozilla::WindowsHandle from "ipc/IPCMessageUtils.h";
 using mozilla::gfx::SurfaceFormat from "mozilla/gfx/Types.h";
 using mozilla::gfx::IntRect from "mozilla/gfx/Rect.h";
 using mozilla::gfx::IntSize from "mozilla/gfx/Point.h";
-using mozilla::ipc::SharedMemoryBasic::Handle from "mozilla/ipc/SharedMemoryBasic.h";
 using gfxImageFormat from "gfxTypes.h";
 
 namespace mozilla {
 namespace layers {
 
 union OverlayHandle {
   int32_t;
   null_t;
@@ -123,34 +122,25 @@ union MemoryOrShmem {
   Shmem;
 };
 
 struct SurfaceDescriptorBuffer {
   BufferDescriptor desc;
   MemoryOrShmem data;
 };
 
-struct SurfaceDescriptorShared
-{
-  IntSize size;
-  int32_t stride;
-  SurfaceFormat format;
-  Handle handle;
-};
-
 union SurfaceDescriptor {
   SurfaceDescriptorBuffer;
   SurfaceDescriptorDIB;
   SurfaceDescriptorD3D10;
   SurfaceDescriptorFileMapping;
   SurfaceDescriptorDXGIYCbCr;
   SurfaceDescriptorX11;
   SurfaceTextureDescriptor;
   EGLImageDescriptor;
   SurfaceDescriptorMacIOSurface;
   SurfaceDescriptorSharedGLTexture;
   SurfaceDescriptorGPUVideo;
-  SurfaceDescriptorShared;
   null_t;
 };
 
 } // namespace
 } // namespace
--- a/gfx/layers/ipc/PCompositorManager.ipdl
+++ b/gfx/layers/ipc/PCompositorManager.ipdl
@@ -1,27 +1,22 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * vim: sw=2 ts=8 et :
  */
 /* 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 protocol PCompositorBridge;
-include LayersSurfaces;
-include "mozilla/GfxMessageUtils.h";
-include "mozilla/layers/WebRenderMessageUtils.h";
 
 using struct mozilla::void_t from "ipc/IPCMessageUtils.h";
 using mozilla::TimeDuration from "mozilla/TimeStamp.h";
 using mozilla::CSSToLayoutDeviceScale from "Units.h";
 using mozilla::gfx::IntSize from "mozilla/gfx/2D.h";
-using mozilla::ipc::SharedMemoryBasic::Handle from "mozilla/ipc/SharedMemoryBasic.h";
 using mozilla::layers::CompositorOptions from "mozilla/layers/CompositorOptions.h";
-using mozilla::wr::ExternalImageId from "mozilla/webrender/WebRenderTypes.h";
 
 namespace mozilla {
 namespace layers {
 
 struct WidgetCompositorOptions {
   CSSToLayoutDeviceScale scale;
   TimeDuration vsyncRate;
   CompositorOptions options;
@@ -67,15 +62,12 @@ parent:
    *   representing the drawable area for Web content.
    * - A "widget" PCompositorBridge is requested by the UI process for each
    *   "top level browser window" for chrome and such.
    * - A "same process widget" PCompositorBridge is requested by the combined
    *   GPU/UI process for each "top level browser window" as above.
    * See gfx/layers/ipc/PCompositorBridge.ipdl for more details.
    */
   async PCompositorBridge(CompositorBridgeOptions options);
-
-  async AddSharedSurface(ExternalImageId aId, SurfaceDescriptorShared aDesc);
-  async RemoveSharedSurface(ExternalImageId aId);
 };
 
 } // layers
 } // mozilla
deleted file mode 100644
--- a/gfx/layers/ipc/SharedSurfacesChild.cpp
+++ /dev/null
@@ -1,214 +0,0 @@
-/* -*- 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 "SharedSurfacesChild.h"
-#include "SharedSurfacesParent.h"
-#include "CompositorManagerChild.h"
-#include "mozilla/layers/SourceSurfaceSharedData.h"
-#include "mozilla/SystemGroup.h"        // for SystemGroup
-
-namespace mozilla {
-namespace layers {
-
-using namespace mozilla::gfx;
-
-class SharedSurfacesChild::SharedUserData final
-{
-public:
-  explicit SharedUserData(const wr::ExternalImageId& aId)
-    : mId(aId)
-    , mShared(false)
-  { }
-
-  ~SharedUserData()
-  {
-    if (mShared) {
-      mShared = false;
-      if (NS_IsMainThread()) {
-        SharedSurfacesChild::Unshare(mId);
-      } else {
-        wr::ExternalImageId id = mId;
-        SystemGroup::Dispatch(TaskCategory::Other,
-                              NS_NewRunnableFunction("DestroySharedUserData",
-                                                     [id]() -> void {
-          SharedSurfacesChild::Unshare(id);
-        }));
-      }
-    }
-  }
-
-  const wr::ExternalImageId& Id() const
-  {
-    return mId;
-  }
-
-  void SetId(const wr::ExternalImageId& aId)
-  {
-    mId = aId;
-    mShared = false;
-  }
-
-  bool IsShared() const
-  {
-    return mShared;
-  }
-
-  void MarkShared()
-  {
-    MOZ_ASSERT(!mShared);
-    mShared = true;
-  }
-
-private:
-  wr::ExternalImageId mId;
-  bool mShared : 1;
-};
-
-/* static */ void
-SharedSurfacesChild::DestroySharedUserData(void* aClosure)
-{
-  MOZ_ASSERT(aClosure);
-  auto data = static_cast<SharedUserData*>(aClosure);
-  delete data;
-}
-
-/* static */ nsresult
-SharedSurfacesChild::Share(SourceSurfaceSharedData* aSurface,
-                           wr::ExternalImageId& aId)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  CompositorManagerChild* manager = CompositorManagerChild::GetInstance();
-  if (NS_WARN_IF(!manager || !manager->CanSend())) {
-    return NS_ERROR_NOT_INITIALIZED;
-  }
-
-  static UserDataKey sSharedKey;
-  SharedUserData* data =
-    static_cast<SharedUserData*>(aSurface->GetUserData(&sSharedKey));
-  if (!data) {
-    data = new SharedUserData(manager->GetNextExternalImageId());
-    aSurface->AddUserData(&sSharedKey, data, DestroySharedUserData);
-  } else if (!manager->OwnsExternalImageId(data->Id())) {
-    // If the id isn't owned by us, that means the bridge was reinitialized, due
-    // to the GPU process crashing. All previous mappings have been released.
-    MOZ_ASSERT(manager->OtherPid() != base::GetCurrentProcId());
-    data->SetId(manager->GetNextExternalImageId());
-  } else if (data->IsShared()) {
-    // It has already been shared with the GPU process, reuse the id.
-    aId = data->Id();
-    return NS_OK;
-  }
-
-  // Ensure that the handle doesn't get released until after we have finished
-  // sending the buffer to the GPU process and/or reallocating it.
-  // FinishedSharing is not a sufficient condition because another thread may
-  // decide we are done while we are in the processing of sharing our newly
-  // reallocated handle. Once it goes out of scope, it may release the handle.
-  SourceSurfaceSharedData::HandleLock lock(aSurface);
-
-  // If we live in the same process, then it is a simple matter of directly
-  // asking the parent instance to store a pointer to the same data, no need
-  // to map the data into our memory space twice.
-  auto pid = manager->OtherPid();
-  if (pid == base::GetCurrentProcId()) {
-    SharedSurfacesParent::AddSameProcess(data->Id(), aSurface);
-    data->MarkShared();
-    aId = data->Id();
-    return NS_OK;
-  }
-
-  // Attempt to share a handle with the GPU process. The handle may or may not
-  // be available -- it will only be available if it is either not yet finalized
-  // and/or if it has been finalized but never used for drawing in process.
-  ipc::SharedMemoryBasic::Handle handle = ipc::SharedMemoryBasic::NULLHandle();
-  nsresult rv = aSurface->ShareToProcess(pid, handle);
-  if (rv == NS_ERROR_NOT_AVAILABLE) {
-    // It is at least as expensive to copy the image to the GPU process if we
-    // have already closed the handle necessary to share, but if we reallocate
-    // the shared buffer to get a new handle, we can save some memory.
-    if (NS_WARN_IF(!aSurface->ReallocHandle())) {
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
-
-    // Reattempt the sharing of the handle to the GPU process.
-    rv = aSurface->ShareToProcess(pid, handle);
-  }
-
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    MOZ_ASSERT(rv != NS_ERROR_NOT_AVAILABLE);
-    return rv;
-  }
-
-  SurfaceFormat format = aSurface->GetFormat();
-  MOZ_RELEASE_ASSERT(format == SurfaceFormat::B8G8R8X8 ||
-                     format == SurfaceFormat::B8G8R8A8, "bad format");
-
-  data->MarkShared();
-  aId = data->Id();
-  manager->SendAddSharedSurface(aId,
-                                SurfaceDescriptorShared(aSurface->GetSize(),
-                                                        aSurface->Stride(),
-                                                        format, handle));
-  return NS_OK;
-}
-
-/* static */ nsresult
-SharedSurfacesChild::Share(ImageContainer* aContainer,
-                           wr::ExternalImageId& aId,
-                           uint32_t& aGeneration)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aContainer);
-
-  if (aContainer->IsAsync()) {
-    return NS_ERROR_NOT_IMPLEMENTED;
-  }
-
-  AutoTArray<ImageContainer::OwningImage,4> images;
-  aContainer->GetCurrentImages(&images, &aGeneration);
-  if (images.IsEmpty()) {
-    return NS_ERROR_NOT_AVAILABLE;
-  }
-
-  RefPtr<gfx::SourceSurface> surface = images[0].mImage->GetAsSourceSurface();
-  if (!surface) {
-    return NS_ERROR_NOT_IMPLEMENTED;
-  }
-
-  if (surface->GetType() != SurfaceType::DATA_SHARED) {
-    return NS_ERROR_NOT_IMPLEMENTED;
-  }
-
-  auto sharedSurface = static_cast<SourceSurfaceSharedData*>(surface.get());
-  return Share(sharedSurface, aId);
-}
-
-/* static */ void
-SharedSurfacesChild::Unshare(const wr::ExternalImageId& aId)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  CompositorManagerChild* manager = CompositorManagerChild::GetInstance();
-  if (MOZ_UNLIKELY(!manager || !manager->CanSend())) {
-    return;
-  }
-
-  if (manager->OtherPid() == base::GetCurrentProcId()) {
-    // We are in the combined UI/GPU process. Call directly to it to remove its
-    // wrapper surface to free the underlying buffer.
-    MOZ_ASSERT(manager->OwnsExternalImageId(aId));
-    SharedSurfacesParent::RemoveSameProcess(aId);
-  } else if (manager->OwnsExternalImageId(aId)) {
-    // Only attempt to release current mappings in the GPU process. It is
-    // possible we had a surface that was previously shared, the GPU process
-    // crashed / was restarted, and then we freed the surface. In that case
-    // we know the mapping has already been freed.
-    manager->SendRemoveSharedSurface(aId);
-  }
-}
-
-} // namespace layers
-} // namespace mozilla
deleted file mode 100644
--- a/gfx/layers/ipc/SharedSurfacesChild.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/* -*- 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/. */
-
-#ifndef MOZILLA_GFX_SHAREDSURFACESCHILD_H
-#define MOZILLA_GFX_SHAREDSURFACESCHILD_H
-
-#include <stddef.h>                     // for size_t
-#include <stdint.h>                     // for uint32_t, uint64_t
-#include "mozilla/Attributes.h"         // for override
-#include "mozilla/RefPtr.h"             // for already_AddRefed
-#include "mozilla/StaticPtr.h"          // for StaticRefPtr
-#include "mozilla/webrender/WebRenderTypes.h" // for wr::ExternalImageId
-
-namespace mozilla {
-namespace gfx {
-class SourceSurfaceSharedData;
-} // namespace gfx
-
-namespace layers {
-
-class CompositorManagerChild;
-
-class SharedSurfacesChild final
-{
-public:
-  static nsresult Share(gfx::SourceSurfaceSharedData* aSurface, wr::ExternalImageId& aId);
-  static nsresult Share(ImageContainer* aContainer, wr::ExternalImageId& aId, uint32_t& aGeneration);
-
-private:
-  SharedSurfacesChild() = delete;
-  ~SharedSurfacesChild() = delete;
-
-  class SharedUserData;
-
-  static void Unshare(const wr::ExternalImageId& aId);
-  static void DestroySharedUserData(void* aClosure);
-};
-
-} // namespace layers
-} // namespace mozilla
-
-#endif
deleted file mode 100644
--- a/gfx/layers/ipc/SharedSurfacesParent.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-/* vim: set ts=2 sw=2 et tw=80: */
-/* -*- 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;
-
-SharedSurfacesParent::SharedSurfacesParent()
-{
-}
-
-SharedSurfacesParent::~SharedSurfacesParent()
-{
-}
-
-/* static */ void
-SharedSurfacesParent::Initialize()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  if (!sInstance) {
-    sInstance = new SharedSurfacesParent();
-  }
-}
-
-/* static */ void
-SharedSurfacesParent::Shutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  sInstance = nullptr;
-}
-
-/* static */ already_AddRefed<DataSourceSurface>
-SharedSurfacesParent::Acquire(const wr::ExternalImageId& aId)
-{
-  MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
-  if (!sInstance) {
-    return nullptr;
-  }
-
-  RefPtr<SourceSurfaceSharedDataWrapper> surface;
-  sInstance->mSurfaces.Get(wr::AsUint64(aId), getter_AddRefs(surface));
-
-  if (surface) {
-    DebugOnly<bool> rv = surface->AddConsumer();
-    MOZ_ASSERT(!rv);
-  }
-
-  return surface.forget();
-}
-
-/* static */ bool
-SharedSurfacesParent::Release(const wr::ExternalImageId& aId)
-{
-  MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
-  if (!sInstance) {
-    return false;
-  }
-
-  uint64_t id = wr::AsUint64(aId);
-  RefPtr<SourceSurfaceSharedDataWrapper> surface;
-  sInstance->mSurfaces.Get(wr::AsUint64(aId), getter_AddRefs(surface));
-  if (!surface) {
-    return false;
-  }
-
-  if (surface->RemoveConsumer()) {
-    sInstance->mSurfaces.Remove(id);
-  }
-
-  return true;
-}
-
-/* static */ void
-SharedSurfacesParent::AddSameProcess(const wr::ExternalImageId& aId,
-                                     SourceSurfaceSharedData* aSurface)
-{
-  MOZ_ASSERT(XRE_IsParentProcess());
-  MOZ_ASSERT(NS_IsMainThread());
-
-  // If the child bridge detects it is in the combined UI/GPU process, then it
-  // will insert a wrapper surface holding the shared memory buffer directly.
-  // This is good because we avoid mapping the same shared memory twice, but
-  // still allow the original surface to be freed and remove the wrapper from
-  // the table when it is no longer needed.
-  RefPtr<SourceSurfaceSharedDataWrapper> surface =
-    new SourceSurfaceSharedDataWrapper();
-  surface->Init(aSurface);
-
-  uint64_t id = wr::AsUint64(aId);
-  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)
-{
-  MOZ_ASSERT(XRE_IsParentProcess());
-  MOZ_ASSERT(NS_IsMainThread());
-
-  const wr::ExternalImageId id(aId);
-  RefPtr<Runnable> task = NS_NewRunnableFunction(
-    "layers::SharedSurfacesParent::RemoveSameProcess",
-    [id]() -> void {
-      Remove(id);
-    });
-
-  CompositorThreadHolder::Loop()->PostTask(task.forget());
-}
-
-/* static */ void
-SharedSurfacesParent::DestroyProcess(base::ProcessId aPid)
-{
-  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,
-                          base::ProcessId aPid)
-{
-  MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
-  MOZ_ASSERT(aPid != base::GetCurrentProcId());
-  if (!sInstance) {
-    return;
-  }
-
-  // Note that the surface wrapper maps in the given handle as read only.
-  RefPtr<SourceSurfaceSharedDataWrapper> surface =
-    new SourceSurfaceSharedDataWrapper();
-  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);
-  MOZ_ASSERT(rv);
-}
-
-} // namespace layers
-} // namespace mozilla
deleted file mode 100644
--- a/gfx/layers/ipc/SharedSurfacesParent.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/* -*- 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/. */
-
-#ifndef MOZILLA_GFX_SHAREDSURFACESPARENT_H
-#define MOZILLA_GFX_SHAREDSURFACESPARENT_H
-
-#include <stdint.h>                     // for uint32_t
-#include "mozilla/Attributes.h"         // for override
-#include "mozilla/StaticPtr.h"          // for StaticAutoPtr
-#include "mozilla/RefPtr.h"             // for already_AddRefed
-#include "mozilla/ipc/SharedMemory.h"   // for SharedMemory, etc
-#include "mozilla/gfx/2D.h"             // for SurfaceFormat
-#include "mozilla/gfx/Point.h"          // for IntSize
-#include "mozilla/webrender/WebRenderTypes.h" // for wr::ExternalImageId
-#include "nsRefPtrHashtable.h"
-
-namespace mozilla {
-namespace gfx {
-class DataSourceSurface;
-class SourceSurfaceSharedData;
-class SourceSurfaceSharedDataWrapper;
-} // namespace gfx
-
-namespace layers {
-
-class SharedSurfacesChild;
-
-class SharedSurfacesParent final
-{
-public:
-  static void Initialize();
-  static void Shutdown();
-
-  static already_AddRefed<gfx::DataSourceSurface>
-  Acquire(const wr::ExternalImageId& aId);
-
-  static bool Release(const wr::ExternalImageId& aId);
-
-  static void Add(const wr::ExternalImageId& aId,
-                  const SurfaceDescriptorShared& aDesc,
-                  base::ProcessId aPid);
-
-  static void Remove(const wr::ExternalImageId& aId);
-
-  static void DestroyProcess(base::ProcessId aPid);
-
-  ~SharedSurfacesParent();
-
-private:
-  friend class SharedSurfacesChild;
-
-  SharedSurfacesParent();
-
-  static void AddSameProcess(const wr::ExternalImageId& aId,
-                             gfx::SourceSurfaceSharedData* aSurface);
-  static void RemoveSameProcess(const wr::ExternalImageId& aId);
-
-  static StaticAutoPtr<SharedSurfacesParent> sInstance;
-
-  nsRefPtrHashtable<nsUint64HashKey, gfx::SourceSurfaceSharedDataWrapper> mSurfaces;
-};
-
-} // namespace layers
-} // namespace mozilla
-
-#endif
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -189,18 +189,16 @@ EXPORTS.mozilla.layers += [
     'ipc/LayersMessageUtils.h',
     'ipc/LayerTransactionChild.h',
     'ipc/LayerTransactionParent.h',
     'ipc/LayerTreeOwnerTracker.h',
     'ipc/RemoteContentController.h',
     'ipc/ShadowLayers.h',
     'ipc/SharedPlanarYCbCrImage.h',
     'ipc/SharedRGBImage.h',
-    'ipc/SharedSurfacesChild.h',
-    'ipc/SharedSurfacesParent.h',
     'ipc/SynchronousTask.h',
     'ipc/TextureForwarder.h',
     'ipc/UiCompositorControllerChild.h',
     'ipc/UiCompositorControllerMessageTypes.h',
     'ipc/UiCompositorControllerParent.h',
     'ipc/VideoBridgeChild.h',
     'ipc/VideoBridgeParent.h',
     'LayerAttributes.h',
@@ -413,18 +411,16 @@ UNIFIED_SOURCES += [
     'ipc/LayerAnimationUtils.cpp',
     'ipc/LayerTransactionChild.cpp',
     'ipc/LayerTransactionParent.cpp',
     'ipc/LayerTreeOwnerTracker.cpp',
     'ipc/RemoteContentController.cpp',
     'ipc/ShadowLayers.cpp',
     'ipc/SharedPlanarYCbCrImage.cpp',
     'ipc/SharedRGBImage.cpp',
-    'ipc/SharedSurfacesChild.cpp',
-    'ipc/SharedSurfacesParent.cpp',
     'ipc/UiCompositorControllerChild.cpp',
     'ipc/UiCompositorControllerParent.cpp',
     'ipc/VideoBridgeChild.cpp',
     'ipc/VideoBridgeParent.cpp',
     'LayerScope.cpp',
     'LayersHelpers.cpp',
     'LayersLogging.cpp',
     'LayerSorter.cpp',
--- a/gfx/layers/wr/WebRenderBridgeParent.cpp
+++ b/gfx/layers/wr/WebRenderBridgeParent.cpp
@@ -19,17 +19,16 @@
 #include "mozilla/layers/APZCTreeManager.h"
 #include "mozilla/layers/Compositor.h"
 #include "mozilla/layers/CompositorBridgeParent.h"
 #include "mozilla/layers/CompositorThread.h"
 #include "mozilla/layers/CompositorVsyncScheduler.h"
 #include "mozilla/layers/ImageBridgeParent.h"
 #include "mozilla/layers/ImageDataSerializer.h"
 #include "mozilla/layers/IpcResourceUpdateQueue.h"
-#include "mozilla/layers/SharedSurfacesParent.h"
 #include "mozilla/layers/TextureHost.h"
 #include "mozilla/layers/AsyncImagePipelineManager.h"
 #include "mozilla/layers/WebRenderImageHost.h"
 #include "mozilla/layers/WebRenderTextureHost.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Unused.h"
 #include "mozilla/webrender/RenderThread.h"
 #include "mozilla/widget/CompositorWidget.h"
@@ -354,51 +353,37 @@ bool
 WebRenderBridgeParent::AddExternalImage(wr::ExternalImageId aExtId, wr::ImageKey aKey,
                                         wr::ResourceUpdateQueue& aResources)
 {
   Range<wr::ImageKey> keys(&aKey, 1);
   // Check if key is obsoleted.
   if (keys[0].mNamespace != mIdNamespace) {
     return true;
   }
+  MOZ_ASSERT(mExternalImageIds.Get(wr::AsUint64(aExtId)).get());
 
-  RefPtr<DataSourceSurface> dSurf = SharedSurfacesParent::Acquire(aExtId);
-  if (dSurf) {
-    if (!gfxEnv::EnableWebRenderRecording()) {
-      wr::ImageDescriptor descriptor(dSurf->GetSize(), dSurf->Stride(),
-                                     dSurf->GetFormat());
-      aResources.AddExternalImage(aKey, descriptor, aExtId,
-                                  wr::WrExternalImageBufferType::ExternalBuffer,
-                                  0);
+  RefPtr<WebRenderImageHost> host = mExternalImageIds.Get(wr::AsUint64(aExtId));
+  if (!host) {
+    NS_ERROR("CompositableHost does not exist");
+    return false;
+  }
+  if (!gfxEnv::EnableWebRenderRecording()) {
+    TextureHost* texture = host->GetAsTextureHostForComposite();
+    if (!texture) {
+      NS_ERROR("TextureHost does not exist");
+      return false;
+    }
+    WebRenderTextureHost* wrTexture = texture->AsWebRenderTextureHost();
+    if (wrTexture) {
+      wrTexture->PushResourceUpdates(aResources, TextureHost::ADD_IMAGE, keys,
+                                     wrTexture->GetExternalImageKey());
       return true;
     }
-  } else {
-    MOZ_ASSERT(mExternalImageIds.Get(wr::AsUint64(aExtId)).get());
-
-    RefPtr<WebRenderImageHost> host = mExternalImageIds.Get(wr::AsUint64(aExtId));
-    if (!host) {
-      NS_ERROR("CompositableHost does not exist");
-      return false;
-    }
-    if (!gfxEnv::EnableWebRenderRecording()) {
-      TextureHost* texture = host->GetAsTextureHostForComposite();
-      if (!texture) {
-        NS_ERROR("TextureHost does not exist");
-        return false;
-      }
-      WebRenderTextureHost* wrTexture = texture->AsWebRenderTextureHost();
-      if (wrTexture) {
-        wrTexture->PushResourceUpdates(aResources, TextureHost::ADD_IMAGE, keys,
-                                       wrTexture->GetExternalImageKey());
-        return true;
-      }
-    }
-    dSurf = host->GetAsSurface();
   }
-
+  RefPtr<DataSourceSurface> dSurf = host->GetAsSurface();
   if (!dSurf) {
     NS_ERROR("TextureHost does not return DataSourceSurface");
     return false;
   }
 
   DataSourceSurface::MappedSurface map;
   if (!dSurf->Map(gfx::DataSourceSurface::MapType::READ, &map)) {
     NS_ERROR("DataSourceSurface failed to map");
@@ -854,21 +839,16 @@ WebRenderBridgeParent::RecvAddExternalIm
 }
 
 mozilla::ipc::IPCResult
 WebRenderBridgeParent::RecvRemoveExternalImageId(const ExternalImageId& aImageId)
 {
   if (mDestroyed) {
     return IPC_OK();
   }
-
-  if (SharedSurfacesParent::Release(aImageId)) {
-    return IPC_OK();
-  }
-
   WebRenderImageHost* wrHost = mExternalImageIds.Get(wr::AsUint64(aImageId)).get();
   if (!wrHost) {
     return IPC_OK();
   }
 
   wrHost->ClearWrBridge();
   mExternalImageIds.Remove(wr::AsUint64(aImageId));
 
--- a/gfx/layers/wr/WebRenderUserData.cpp
+++ b/gfx/layers/wr/WebRenderUserData.cpp
@@ -5,17 +5,16 @@
 
 #include "WebRenderUserData.h"
 
 #include "mozilla/layers/ImageClient.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
 #include "mozilla/layers/WebRenderLayerManager.h"
 #include "mozilla/layers/WebRenderMessages.h"
 #include "mozilla/layers/IpcResourceUpdateQueue.h"
-#include "mozilla/layers/SharedSurfacesChild.h"
 #include "nsDisplayListInvalidation.h"
 #include "WebRenderCanvasRenderer.h"
 
 namespace mozilla {
 namespace layers {
 
 WebRenderUserData::WebRenderUserData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem)
   : mWRManager(aWRManager)
@@ -45,17 +44,16 @@ WebRenderUserData::RemoveFromTable()
 WebRenderBridgeChild*
 WebRenderUserData::WrBridge() const
 {
   return mWRManager->WrBridge();
 }
 
 WebRenderImageData::WebRenderImageData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem)
   : WebRenderUserData(aWRManager, aItem)
-  , mGeneration(0)
 {
 }
 
 WebRenderImageData::~WebRenderImageData()
 {
   ClearCachedResources();
 }
 
@@ -78,65 +76,46 @@ WebRenderImageData::ClearCachedResources
   }
 }
 
 Maybe<wr::ImageKey>
 WebRenderImageData::UpdateImageKey(ImageContainer* aContainer,
                                    wr::IpcResourceUpdateQueue& aResources,
                                    bool aForceUpdate)
 {
-  MOZ_ASSERT(aContainer);
+  CreateImageClientIfNeeded();
+  CreateExternalImageIfNeeded();
 
   if (mContainer != aContainer) {
     mContainer = aContainer;
   }
 
-  wr::ExternalImageId externalId;
-  uint32_t generation;
-  nsresult rv = SharedSurfacesChild::Share(aContainer, externalId, generation);
-  if (NS_SUCCEEDED(rv)) {
-    if (mExternalImageId.isSome() && mExternalImageId.ref() == externalId) {
-      // The image container has the same surface as before, we can reuse the
-      // key if the generation matches and the caller allows us.
-      if (mKey && mGeneration == generation && !aForceUpdate) {
-        return mKey;
-      }
-    } else {
-      // The image container has a new surface, generate a new image key.
-      mExternalImageId = Some(externalId);
-    }
+  if (!mImageClient || !mExternalImageId) {
+    return Nothing();
+  }
 
-    mGeneration = generation;
-  } else if (rv == NS_ERROR_NOT_IMPLEMENTED) {
-    CreateImageClientIfNeeded();
-    CreateExternalImageIfNeeded();
+  MOZ_ASSERT(mImageClient->AsImageClientSingle());
+  MOZ_ASSERT(aContainer);
+
+  ImageClientSingle* imageClient = mImageClient->AsImageClientSingle();
+  uint32_t oldCounter = imageClient->GetLastUpdateGenerationCounter();
 
-    if (!mImageClient || !mExternalImageId) {
-      return Nothing();
+  bool ret = imageClient->UpdateImage(aContainer, /* unused */0);
+  if (!ret || imageClient->IsEmpty()) {
+    // Delete old key
+    if (mKey) {
+      mWRManager->AddImageKeyForDiscard(mKey.value());
+      mKey = Nothing();
     }
-
-    MOZ_ASSERT(mImageClient->AsImageClientSingle());
-
-    ImageClientSingle* imageClient = mImageClient->AsImageClientSingle();
-    uint32_t oldCounter = imageClient->GetLastUpdateGenerationCounter();
+    return Nothing();
+  }
 
-    bool ret = imageClient->UpdateImage(aContainer, /* unused */0);
-    if (!ret || imageClient->IsEmpty()) {
-      // Delete old key
-      if (mKey) {
-        mWRManager->AddImageKeyForDiscard(mKey.value());
-        mKey = Nothing();
-      }
-      return Nothing();
-    }
-
-    // Reuse old key if generation is not updated.
-    if (!aForceUpdate && oldCounter == imageClient->GetLastUpdateGenerationCounter() && mKey) {
-      return mKey;
-    }
+  // Reuse old key if generation is not updated.
+  if (!aForceUpdate && oldCounter == imageClient->GetLastUpdateGenerationCounter() && mKey) {
+    return mKey;
   }
 
   // Delete old key, we are generating a new key.
   // TODO(nical): noooo... we need to reuse image keys.
   if (mKey) {
     mWRManager->AddImageKeyForDiscard(mKey.value());
   }
 
--- a/gfx/layers/wr/WebRenderUserData.h
+++ b/gfx/layers/wr/WebRenderUserData.h
@@ -102,17 +102,16 @@ public:
 protected:
   void CreateExternalImageIfNeeded();
 
   wr::MaybeExternalImageId mExternalImageId;
   Maybe<wr::ImageKey> mKey;
   RefPtr<ImageClient> mImageClient;
   Maybe<wr::PipelineId> mPipelineId;
   RefPtr<ImageContainer> mContainer;
-  uint32_t mGeneration;
 };
 
 class WebRenderFallbackData : public WebRenderImageData
 {
 public:
   explicit WebRenderFallbackData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem);
   virtual ~WebRenderFallbackData();
 
--- a/gfx/webrender_bindings/RenderBufferTextureHost.cpp
+++ b/gfx/webrender_bindings/RenderBufferTextureHost.cpp
@@ -38,35 +38,35 @@ RenderBufferTextureHost::RenderBufferTex
   }
 }
 
 RenderBufferTextureHost::~RenderBufferTextureHost()
 {
   MOZ_COUNT_DTOR_INHERITED(RenderBufferTextureHost, RenderTextureHost);
 }
 
-wr::WrExternalImage
-RenderBufferTextureHost::Lock(uint8_t aChannelIndex, gl::GLContext* aGL)
+bool
+RenderBufferTextureHost::Lock()
 {
   if (!mLocked) {
     if (!GetBuffer()) {
       // We hit some problems to get the shmem.
-      return RawDataToWrExternalImage(nullptr, 0);
+      return false;
     }
     if (mFormat != gfx::SurfaceFormat::YUV) {
       mSurface = gfx::Factory::CreateWrappingDataSourceSurface(GetBuffer(),
                                                                layers::ImageDataSerializer::GetRGBStride(mDescriptor.get_RGBDescriptor()),
                                                                mSize,
                                                                mFormat);
       if (NS_WARN_IF(!mSurface)) {
-        return RawDataToWrExternalImage(nullptr, 0);
+        return false;
       }
       if (NS_WARN_IF(!mSurface->Map(gfx::DataSourceSurface::MapType::READ_WRITE, &mMap))) {
         mSurface = nullptr;
-        return RawDataToWrExternalImage(nullptr, 0);
+        return false;
       }
     } else {
       const layers::YCbCrDescriptor& desc = mDescriptor.get_YCbCrDescriptor();
 
       mYSurface = gfx::Factory::CreateWrappingDataSourceSurface(layers::ImageDataSerializer::GetYChannel(GetBuffer(), desc),
                                                                 desc.yStride(),
                                                                 desc.ySize(),
                                                                 gfx::SurfaceFormat::A8);
@@ -75,30 +75,29 @@ RenderBufferTextureHost::Lock(uint8_t aC
                                                                  desc.cbCrSize(),
                                                                  gfx::SurfaceFormat::A8);
       mCrSurface = gfx::Factory::CreateWrappingDataSourceSurface(layers::ImageDataSerializer::GetCrChannel(GetBuffer(), desc),
                                                                  desc.cbCrStride(),
                                                                  desc.cbCrSize(),
                                                                  gfx::SurfaceFormat::A8);
       if (NS_WARN_IF(!mYSurface || !mCbSurface || !mCrSurface)) {
         mYSurface = mCbSurface = mCrSurface = nullptr;
-        return RawDataToWrExternalImage(nullptr, 0);
+        return false;
       }
       if (NS_WARN_IF(!mYSurface->Map(gfx::DataSourceSurface::MapType::READ_WRITE, &mYMap) ||
                      !mCbSurface->Map(gfx::DataSourceSurface::MapType::READ_WRITE, &mCbMap) ||
                      !mCrSurface->Map(gfx::DataSourceSurface::MapType::READ_WRITE, &mCrMap))) {
         mYSurface = mCbSurface = mCrSurface = nullptr;
-        return RawDataToWrExternalImage(nullptr, 0);
+        return false;
       }
     }
     mLocked = true;
   }
 
-  RenderBufferData data = GetBufferDataForRender(aChannelIndex);
-  return RawDataToWrExternalImage(data.mData, data.mBufferSize);
+  return true;
 }
 
 void
 RenderBufferTextureHost::Unlock()
 {
   if (mLocked) {
     if (mSurface) {
       mSurface->Unmap();
--- a/gfx/webrender_bindings/RenderBufferTextureHost.h
+++ b/gfx/webrender_bindings/RenderBufferTextureHost.h
@@ -12,18 +12,23 @@ namespace mozilla {
 namespace wr {
 
 class RenderBufferTextureHost final : public RenderTextureHost
 {
 public:
   RenderBufferTextureHost(uint8_t* aBuffer,
                           const layers::BufferDescriptor& aDescriptor);
 
-  wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override;
-  void Unlock() override;
+  virtual bool Lock() override;
+  virtual void Unlock() override;
+
+  virtual RenderBufferTextureHost* AsBufferTextureHost() override
+  {
+    return this;
+  }
 
   class RenderBufferData
   {
   public:
     RenderBufferData(uint8_t* aData, size_t aBufferSize)
       : mData(aData)
       , mBufferSize(aBufferSize)
     {
--- a/gfx/webrender_bindings/RenderD3D11TextureHostOGL.cpp
+++ b/gfx/webrender_bindings/RenderD3D11TextureHostOGL.cpp
@@ -54,16 +54,27 @@ RenderDXGITextureHostOGL::RenderDXGIText
 }
 
 RenderDXGITextureHostOGL::~RenderDXGITextureHostOGL()
 {
   MOZ_COUNT_DTOR_INHERITED(RenderDXGITextureHostOGL, RenderTextureHostOGL);
   DeleteTextureHandle();
 }
 
+void
+RenderDXGITextureHostOGL::SetGLContext(gl::GLContext* aContext)
+{
+  if (mGL.get() != aContext) {
+    // Release the texture handle in the previous gl context.
+    DeleteTextureHandle();
+    mGL = aContext;
+    mGL->MakeCurrent();
+  }
+}
+
 bool
 RenderDXGITextureHostOGL::EnsureLockable()
 {
   if (mTextureHandle[0]) {
     return true;
   }
 
   const auto& egl = &gl::sEGLLibrary;
@@ -166,44 +177,37 @@ RenderDXGITextureHostOGL::EnsureLockable
     // Now, we could get the NV12 gl handle from the stream.
     egl->fStreamConsumerAcquireKHR(egl->Display(), mStream);
     MOZ_ASSERT(egl->fGetError() == LOCAL_EGL_SUCCESS);
   }
 
   return true;
 }
 
-wr::WrExternalImage
-RenderDXGITextureHostOGL::Lock(uint8_t aChannelIndex, gl::GLContext* aGL)
+bool
+RenderDXGITextureHostOGL::Lock()
 {
-  if (mGL.get() != aGL) {
-    // Release the texture handle in the previous gl context.
-    DeleteTextureHandle();
-    mGL = aGL;
-    mGL->MakeCurrent();
+  if (!EnsureLockable()) {
+    return false;
   }
 
-  if (!EnsureLockable()) {
-    return NativeTextureToWrExternalImage(0, 0, 0, 0, 0);
+  if (mLocked) {
+    return true;
   }
 
-  if (!mLocked) {
-    if (mKeyedMutex) {
-      HRESULT hr = mKeyedMutex->AcquireSync(0, 100);
-      if (hr != S_OK) {
-        gfxCriticalError() << "RenderDXGITextureHostOGL AcquireSync timeout, hr=" << gfx::hexa(hr);
-        return NativeTextureToWrExternalImage(0, 0, 0, 0, 0);
-      }
+  if (mKeyedMutex) {
+    HRESULT hr = mKeyedMutex->AcquireSync(0, 100);
+    if (hr != S_OK) {
+      gfxCriticalError() << "RenderDXGITextureHostOGL AcquireSync timeout, hr=" << gfx::hexa(hr);
+      return false;
     }
-    mLocked = true;
   }
+  mLocked = true;
 
-  gfx::IntSize size = GetSize(aChannelIndex);
-  return NativeTextureToWrExternalImage(GetGLHandle(aChannelIndex), 0, 0,
-                                        size.width, size.height);
+  return true;
 }
 
 void
 RenderDXGITextureHostOGL::Unlock()
 {
   if (mLocked) {
     if (mKeyedMutex) {
       mKeyedMutex->ReleaseSync(0);
@@ -280,16 +284,27 @@ RenderDXGIYCbCrTextureHostOGL::RenderDXG
 }
 
 RenderDXGIYCbCrTextureHostOGL::~RenderDXGIYCbCrTextureHostOGL()
 {
   MOZ_COUNT_CTOR_INHERITED(RenderDXGIYCbCrTextureHostOGL, RenderTextureHostOGL);
   DeleteTextureHandle();
 }
 
+void
+RenderDXGIYCbCrTextureHostOGL::SetGLContext(gl::GLContext* aContext)
+{
+  if (mGL.get() != aContext) {
+    // Release the texture handle in the previous gl context.
+    DeleteTextureHandle();
+    mGL = aContext;
+    mGL->MakeCurrent();
+  }
+}
+
 bool
 RenderDXGIYCbCrTextureHostOGL::EnsureLockable()
 {
   if (mTextureHandles[0]) {
     return true;
   }
 
   const auto& egl = &gl::sEGLLibrary;
@@ -347,46 +362,39 @@ RenderDXGIYCbCrTextureHostOGL::EnsureLoc
     // Now, we could get the R8 gl handle from the stream.
     egl->fStreamConsumerAcquireKHR(egl->Display(), mStreams[i]);
     MOZ_ASSERT(egl->fGetError() == LOCAL_EGL_SUCCESS);
   }
 
   return true;
 }
 
-wr::WrExternalImage
-RenderDXGIYCbCrTextureHostOGL::Lock(uint8_t aChannelIndex, gl::GLContext* aGL)
+bool
+RenderDXGIYCbCrTextureHostOGL::Lock()
 {
-  if (mGL.get() != aGL) {
-    // Release the texture handle in the previous gl context.
-    DeleteTextureHandle();
-    mGL = aGL;
-    mGL->MakeCurrent();
+  if (!EnsureLockable()) {
+    return false;
   }
 
-  if (!EnsureLockable()) {
-    return NativeTextureToWrExternalImage(0, 0, 0, 0, 0);
+  if (mLocked) {
+    return true;
   }
 
-  if (!mLocked) {
-    if (mKeyedMutexs[0]) {
-      for (const auto& mutex : mKeyedMutexs) {
-        HRESULT hr = mutex->AcquireSync(0, 100);
-        if (hr != S_OK) {
-          gfxCriticalError() << "RenderDXGIYCbCrTextureHostOGL AcquireSync timeout, hr=" << gfx::hexa(hr);
-          return NativeTextureToWrExternalImage(0, 0, 0, 0, 0);
-        }
+  if (mKeyedMutexs[0]) {
+    for (const auto& mutex : mKeyedMutexs) {
+      HRESULT hr = mutex->AcquireSync(0, 100);
+      if (hr != S_OK) {
+        gfxCriticalError() << "RenderDXGIYCbCrTextureHostOGL AcquireSync timeout, hr=" << gfx::hexa(hr);
+        return false;
       }
     }
-    mLocked = true;
   }
+  mLocked = true;
 
-  gfx::IntSize size = GetSize(aChannelIndex);
-  return NativeTextureToWrExternalImage(GetGLHandle(aChannelIndex), 0, 0,
-                                        size.width, size.height);
+  return true;
 }
 
 void
 RenderDXGIYCbCrTextureHostOGL::Unlock()
 {
   if (mLocked) {
     if (mKeyedMutexs[0]) {
       for (const auto& mutex : mKeyedMutexs) {
--- a/gfx/webrender_bindings/RenderD3D11TextureHostOGL.h
+++ b/gfx/webrender_bindings/RenderD3D11TextureHostOGL.h
@@ -18,18 +18,20 @@ namespace wr {
 
 class RenderDXGITextureHostOGL final : public RenderTextureHostOGL
 {
 public:
   explicit RenderDXGITextureHostOGL(WindowsHandle aHandle,
                                     gfx::SurfaceFormat aFormat,
                                     gfx::IntSize aSize);
 
-  wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override;
-  void Unlock() override;
+  virtual void SetGLContext(gl::GLContext* aContext) override;
+
+  virtual bool Lock() override;
+  virtual void Unlock() override;
 
   virtual gfx::IntSize GetSize(uint8_t aChannelIndex) const;
   virtual GLuint GetGLHandle(uint8_t aChannelIndex) const;
 
 private:
   virtual ~RenderDXGITextureHostOGL();
 
   bool EnsureLockable();
@@ -56,17 +58,19 @@ private:
 };
 
 class RenderDXGIYCbCrTextureHostOGL final : public RenderTextureHostOGL
 {
 public:
   explicit RenderDXGIYCbCrTextureHostOGL(WindowsHandle (&aHandles)[3],
                                          gfx::IntSize aSize);
 
-  wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override;
+  virtual void SetGLContext(gl::GLContext* aContext) override;
+
+  virtual bool Lock() override;
   virtual void Unlock() override;
 
   virtual gfx::IntSize GetSize(uint8_t aChannelIndex) const;
   virtual GLuint GetGLHandle(uint8_t aChannelIndex) const;
 
 private:
   virtual ~RenderDXGIYCbCrTextureHostOGL();
 
--- a/gfx/webrender_bindings/RenderMacIOSurfaceTextureHostOGL.cpp
+++ b/gfx/webrender_bindings/RenderMacIOSurfaceTextureHostOGL.cpp
@@ -66,53 +66,55 @@ RenderMacIOSurfaceTextureHostOGL::GetSiz
 
   if (!mSurface) {
     return gfx::IntSize();
   }
   return gfx::IntSize(mSurface->GetDevicePixelWidth(aChannelIndex),
                       mSurface->GetDevicePixelHeight(aChannelIndex));
 }
 
-wr::WrExternalImage
-RenderMacIOSurfaceTextureHostOGL::Lock(uint8_t aChannelIndex, gl::GLContext* aGL)
+bool
+RenderMacIOSurfaceTextureHostOGL::Lock()
 {
-  if (mGL.get() != aGL) {
-    // release the texture handle in the previous gl context
-    DeleteTextureHandle();
-    mGL = aGL;
-    mGL->MakeCurrent();
-  }
-
   if (!mSurface || !mGL || !mGL->MakeCurrent()) {
-    return NativeTextureToWrExternalImage(0, 0, 0, 0, 0);
+    return false;
   }
 
   if (!mTextureHandles[0]) {
     MOZ_ASSERT(gl::GLContextCGL::Cast(mGL.get())->GetCGLContext());
 
     // The result of GetPlaneCount() is 0 for single plane format, but it will
     // be 2 if the format has 2 planar data.
     CreateTextureForPlane(0, mGL, mSurface, &(mTextureHandles[0]));
     for (size_t i = 1; i < mSurface->GetPlaneCount(); ++i) {
       CreateTextureForPlane(i, mGL, mSurface, &(mTextureHandles[i]));
     }
   }
 
-  gfx::IntSize size = GetSize(aChannelIndex);
-  return NativeTextureToWrExternalImage(GetGLHandle(aChannelIndex), 0, 0,
-                                        size.width, size.height);
+  return true;
 }
 
 void
 RenderMacIOSurfaceTextureHostOGL::Unlock()
 {
 
 }
 
 void
+RenderMacIOSurfaceTextureHostOGL::SetGLContext(gl::GLContext* aContext)
+{
+  if (mGL.get() != aContext) {
+    // release the texture handle in the previous gl context
+    DeleteTextureHandle();
+    mGL = aContext;
+    mGL->MakeCurrent();
+  }
+}
+
+void
 RenderMacIOSurfaceTextureHostOGL::DeleteTextureHandle()
 {
   if (mTextureHandles[0] != 0 && mGL && mGL->MakeCurrent()) {
     // Calling glDeleteTextures on 0 isn't an error. So, just make them a single
     // call.
     mGL->fDeleteTextures(3, mTextureHandles);
     for (size_t i = 0; i < 3; ++i) {
       mTextureHandles[i] = 0;
--- a/gfx/webrender_bindings/RenderMacIOSurfaceTextureHostOGL.h
+++ b/gfx/webrender_bindings/RenderMacIOSurfaceTextureHostOGL.h
@@ -18,18 +18,20 @@ class SurfaceDescriptorMacIOSurface;
 
 namespace wr {
 
 class RenderMacIOSurfaceTextureHostOGL final : public RenderTextureHostOGL
 {
 public:
   explicit RenderMacIOSurfaceTextureHostOGL(MacIOSurface* aSurface);
 
-  wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override;
-  void Unlock() override;
+  virtual bool Lock() override;
+  virtual void Unlock() override;
+
+  virtual void SetGLContext(gl::GLContext* aContext) override;
 
   virtual gfx::IntSize GetSize(uint8_t aChannelIndex) const override;
   virtual GLuint GetGLHandle(uint8_t aChannelIndex) const override;
 
 private:
   virtual ~RenderMacIOSurfaceTextureHostOGL();
   void DeleteTextureHandle();
 
deleted file mode 100644
--- a/gfx/webrender_bindings/RenderSharedSurfaceTextureHost.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -*- 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 "RenderSharedSurfaceTextureHost.h"
-
-#include "mozilla/gfx/Logging.h"
-#include "mozilla/layers/ImageDataSerializer.h"
-#include "mozilla/layers/SourceSurfaceSharedData.h"
-
-namespace mozilla {
-namespace wr {
-
-RenderSharedSurfaceTextureHost::RenderSharedSurfaceTextureHost(gfx::SourceSurfaceSharedDataWrapper* aSurface)
-  : mSurface(aSurface)
-  , mLocked(false)
-{
-  MOZ_COUNT_CTOR_INHERITED(RenderSharedSurfaceTextureHost, RenderTextureHost);
-  MOZ_ASSERT(aSurface);
-}
-
-RenderSharedSurfaceTextureHost::~RenderSharedSurfaceTextureHost()
-{
-  MOZ_COUNT_DTOR_INHERITED(RenderSharedSurfaceTextureHost, RenderTextureHost);
-}
-
-wr::WrExternalImage
-RenderSharedSurfaceTextureHost::Lock(uint8_t aChannelIndex, gl::GLContext* aGL)
-{
-  if (!mLocked) {
-    if (NS_WARN_IF(!mSurface->Map(gfx::DataSourceSurface::MapType::READ_WRITE,
-                                  &mMap))) {
-      return RawDataToWrExternalImage(nullptr, 0);
-    }
-    mLocked = true;
-  }
-
-  return RawDataToWrExternalImage(mMap.mData,
-                                  mMap.mStride * mSurface->GetSize().height);
-}
-
-void
-RenderSharedSurfaceTextureHost::Unlock()
-{
-  if (mLocked) {
-    mSurface->Unmap();
-    mLocked = false;
-  }
-}
-
-} // namespace wr
-} // namespace mozilla
deleted file mode 100644
--- a/gfx/webrender_bindings/RenderSharedSurfaceTextureHost.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -*- 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/. */
-
-#ifndef MOZILLA_GFX_RENDERSHAREDSURFACETEXTUREHOST_H
-#define MOZILLA_GFX_RENDERSHAREDSURFACETEXTUREHOST_H
-
-#include "RenderTextureHost.h"
-
-namespace mozilla {
-namespace gfx {
-class SourceSurfaceSharedDataWrapper;
-}
-
-namespace wr {
-
-class RenderSharedSurfaceTextureHost final : public RenderTextureHost
-{
-public:
-  explicit RenderSharedSurfaceTextureHost(gfx::SourceSurfaceSharedDataWrapper* aSurface);
-
-  wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override;
-  void Unlock() override;
-
-private:
-  ~RenderSharedSurfaceTextureHost() override;
-
-  RefPtr<gfx::SourceSurfaceSharedDataWrapper> mSurface;
-  gfx::DataSourceSurface::MappedSurface mMap;
-  bool mLocked;
-};
-
-} // namespace wr
-} // namespace mozilla
-
-#endif // MOZILLA_GFX_RENDERSHAREDSURFACETEXTUREHOST_H
--- a/gfx/webrender_bindings/RenderTextureHost.h
+++ b/gfx/webrender_bindings/RenderTextureHost.h
@@ -7,36 +7,34 @@
 #define MOZILLA_GFX_RENDERTEXTUREHOST_H
 
 #include "nsISupportsImpl.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/layers/LayersSurfaces.h"
 #include "mozilla/RefPtr.h"
 
 namespace mozilla {
-
-namespace gl {
-class GLContext;
-}
-
 namespace wr {
 
 class RenderBufferTextureHost;
 class RenderTextureHostOGL;
 
 class RenderTextureHost
 {
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RenderTextureHost)
 
 public:
   RenderTextureHost();
 
-  virtual wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) = 0;
+  virtual bool Lock() = 0;
   virtual void Unlock() = 0;
 
+  virtual RenderBufferTextureHost* AsBufferTextureHost() { return nullptr; }
+  virtual RenderTextureHostOGL* AsTextureHostOGL() { return nullptr; }
+
 protected:
   virtual ~RenderTextureHost();
 };
 
 } // namespace wr
 } // namespace mozilla
 
 #endif // MOZILLA_GFX_RENDERTEXTUREHOST_H
--- a/gfx/webrender_bindings/RenderTextureHostOGL.h
+++ b/gfx/webrender_bindings/RenderTextureHostOGL.h
@@ -16,19 +16,23 @@ class GLContext;
 
 namespace wr {
 
 class RenderTextureHostOGL : public RenderTextureHost
 {
 public:
   RenderTextureHostOGL();
 
+  virtual void SetGLContext(gl::GLContext* aContext) = 0;
+
   virtual gfx::IntSize GetSize(uint8_t aChannelIndex) const = 0;
   virtual GLuint GetGLHandle(uint8_t aChannelIndex) const = 0;
 
+  virtual RenderTextureHostOGL* AsTextureHostOGL()  override { return this; }
+
 protected:
   virtual ~RenderTextureHostOGL();
 };
 
 } // namespace wr
 } // namespace mozilla
 
 #endif // MOZILLA_GFX_RENDERTEXTUREHOSTOGL_H
--- a/gfx/webrender_bindings/RendererOGL.cpp
+++ b/gfx/webrender_bindings/RendererOGL.cpp
@@ -17,18 +17,47 @@
 
 namespace mozilla {
 namespace wr {
 
 wr::WrExternalImage LockExternalImage(void* aObj, wr::WrExternalImageId aId, uint8_t aChannelIndex)
 {
   RendererOGL* renderer = reinterpret_cast<RendererOGL*>(aObj);
   RenderTextureHost* texture = renderer->GetRenderTexture(aId);
-  MOZ_ASSERT(texture);
-  return texture->Lock(aChannelIndex, renderer->mGL);
+
+  if (texture->AsBufferTextureHost()) {
+    RenderBufferTextureHost* bufferTexture = texture->AsBufferTextureHost();
+    MOZ_ASSERT(bufferTexture);
+
+    if (bufferTexture->Lock()) {
+      RenderBufferTextureHost::RenderBufferData data =
+          bufferTexture->GetBufferDataForRender(aChannelIndex);
+
+      return RawDataToWrExternalImage(data.mData, data.mBufferSize);
+    } else {
+      return RawDataToWrExternalImage(nullptr, 0);
+    }
+  } else {
+    // texture handle case
+    RenderTextureHostOGL* textureOGL = texture->AsTextureHostOGL();
+    MOZ_ASSERT(textureOGL);
+
+    textureOGL->SetGLContext(renderer->mGL);
+    gfx::IntSize size = textureOGL->GetSize(aChannelIndex);
+    if (textureOGL->Lock()) {
+      return NativeTextureToWrExternalImage(textureOGL->GetGLHandle(aChannelIndex),
+                                            0, 0,
+                                            size.width, size.height);
+    } else {
+      // Just use 0 for the gl handle if the lock() was failed.
+      return NativeTextureToWrExternalImage(0,
+                                            0, 0,
+                                            size.width, size.height);
+    }
+  }
 }
 
 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();
--- a/gfx/webrender_bindings/moz.build
+++ b/gfx/webrender_bindings/moz.build
@@ -5,31 +5,29 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 with Files('**'):
     BUG_COMPONENT = ('Core', 'Graphics: WebRender')
 
 EXPORTS.mozilla.webrender += [
     'RenderBufferTextureHost.h',
     'RendererOGL.h',
-    'RenderSharedSurfaceTextureHost.h',
     'RenderTextureHost.h',
     'RenderTextureHostOGL.h',
     'RenderThread.h',
     'webrender_ffi.h',
     'webrender_ffi_generated.h',
     'WebRenderAPI.h',
     'WebRenderTypes.h',
 ]
 
 UNIFIED_SOURCES += [
     'Moz2DImageRenderer.cpp',
     'RenderBufferTextureHost.cpp',
     'RendererOGL.cpp',
-    'RenderSharedSurfaceTextureHost.cpp',
     'RenderTextureHost.cpp',
     'RenderTextureHostOGL.cpp',
     'RenderThread.cpp',
     'WebRenderAPI.cpp',
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     EXPORTS.mozilla.webrender += [