Bug 1647491 - Hold ref to previous webgl frontbuffer while in-flight. r=lsalzman, a=RyanVM
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 02 Jul 2020 01:45:36 +0000
changeset 601901 2baeb9bff2ee062cd8cfdd0e05497c105ec15363
parent 601900 826468e886b2c1b9346f396702b90fc62ffe8c79
child 601902 c5afbc5bd6936b4e3aad96b8d8d4ff2ec17f7a85
push id13344
push userryanvm@gmail.com
push dateFri, 03 Jul 2020 00:16:09 +0000
treeherdermozilla-beta@51bedc350693 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman, RyanVM
bugs1647491
milestone79.0
Bug 1647491 - Hold ref to previous webgl frontbuffer while in-flight. r=lsalzman, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D81921
gfx/gl/GLScreenBuffer.cpp
gfx/gl/GLScreenBuffer.h
--- a/gfx/gl/GLScreenBuffer.cpp
+++ b/gfx/gl/GLScreenBuffer.cpp
@@ -43,50 +43,55 @@ UniquePtr<SwapChainPresenter> SwapChain:
     surf.reset(uniquePtrSurf.release());
   }
   mPool.push(surf);
   while (mPool.size() > kPoolSize) {
     mPool.pop();
   }
 
   auto ret = MakeUnique<SwapChainPresenter>(*this);
-  ret->SwapBackBuffer(std::move(surf));
+  const auto old = ret->SwapBackBuffer(surf);
+  MOZ_ALWAYS_TRUE(!old);
   return ret;
 }
 
-void SwapChain::ClearPool() { mPool = {}; }
+void SwapChain::ClearPool() {
+  mPool = {};
+  mPrevFrontBuffer = nullptr;
+}
 
 // -
 
 SwapChainPresenter::SwapChainPresenter(SwapChain& swapChain)
     : mSwapChain(&swapChain) {
   MOZ_RELEASE_ASSERT(mSwapChain->mPresenter == nullptr);
   mSwapChain->mPresenter = this;
 }
 
 SwapChainPresenter::~SwapChainPresenter() {
   if (!mSwapChain) return;
   MOZ_RELEASE_ASSERT(mSwapChain->mPresenter == this);
   mSwapChain->mPresenter = nullptr;
 
   auto newFront = SwapBackBuffer(nullptr);
   if (newFront) {
-    mSwapChain->mFrontBuffer = std::move(newFront);
+    mSwapChain->mPrevFrontBuffer = mSwapChain->mFrontBuffer;
+    mSwapChain->mFrontBuffer = newFront;
   }
 }
 
 std::shared_ptr<SharedSurface> SwapChainPresenter::SwapBackBuffer(
     std::shared_ptr<SharedSurface> back) {
   if (mBackBuffer) {
     mBackBuffer->UnlockProd();
     mBackBuffer->ProducerRelease();
     mBackBuffer->Commit();
   }
-  auto old = std::move(mBackBuffer);
-  mBackBuffer = std::move(back);
+  auto old = mBackBuffer;
+  mBackBuffer = back;
   if (mBackBuffer) {
     mBackBuffer->WaitForBufferOwnership();
     mBackBuffer->ProducerAcquire();
     mBackBuffer->LockProd();
   }
   return old;
 }
 
--- a/gfx/gl/GLScreenBuffer.h
+++ b/gfx/gl/GLScreenBuffer.h
@@ -52,22 +52,23 @@ class SwapChainPresenter final {
 
 class SwapChain final {
   friend class SwapChainPresenter;
 
  public:
   UniquePtr<SurfaceFactory> mFactory;
 
  private:
+  std::queue<std::shared_ptr<SharedSurface>> mPool;
   std::shared_ptr<SharedSurface> mFrontBuffer;
+ public:
+  std::shared_ptr<SharedSurface> mPrevFrontBuffer; // Hold this ref while it's in-flight.
+ private:
   SwapChainPresenter* mPresenter = nullptr;
 
- private:
-  std::queue<std::shared_ptr<SharedSurface>> mPool;
-
  public:
   SwapChain();
   virtual ~SwapChain();
 
   void ClearPool();
   const auto& FrontBuffer() const { return mFrontBuffer; }
   UniquePtr<SwapChainPresenter> Acquire(const gfx::IntSize&);
 };