From 335a0af676b942903fbabcc1cee75775998a0e4e Mon Sep 17 00:00:00 2001 From: Jeff Gilbert Date: Thu, 2 Jul 2020 01:45:36 +0000 Subject: [PATCH] Bug 1647491 - Hold ref to previous webgl frontbuffer while in-flight. r=lsalzman Differential Revision: https://phabricator.services.mozilla.com/D81921 --- gfx/gl/GLScreenBuffer.cpp | 15 ++++++++++----- gfx/gl/GLScreenBuffer.h | 9 +++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/gfx/gl/GLScreenBuffer.cpp b/gfx/gl/GLScreenBuffer.cpp index dc468baa7a44..0398dd7dc6a2 100644 --- a/gfx/gl/GLScreenBuffer.cpp +++ b/gfx/gl/GLScreenBuffer.cpp @@ -48,11 +48,15 @@ UniquePtr SwapChain::Acquire(const gfx::IntSize& size) { } auto ret = MakeUnique(*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; +} // - @@ -69,7 +73,8 @@ SwapChainPresenter::~SwapChainPresenter() { auto newFront = SwapBackBuffer(nullptr); if (newFront) { - mSwapChain->mFrontBuffer = std::move(newFront); + mSwapChain->mPrevFrontBuffer = mSwapChain->mFrontBuffer; + mSwapChain->mFrontBuffer = newFront; } } @@ -80,8 +85,8 @@ std::shared_ptr SwapChainPresenter::SwapBackBuffer( mBackBuffer->ProducerRelease(); mBackBuffer->Commit(); } - auto old = std::move(mBackBuffer); - mBackBuffer = std::move(back); + auto old = mBackBuffer; + mBackBuffer = back; if (mBackBuffer) { mBackBuffer->WaitForBufferOwnership(); mBackBuffer->ProducerAcquire(); diff --git a/gfx/gl/GLScreenBuffer.h b/gfx/gl/GLScreenBuffer.h index ea67518ab66e..916e1898e70a 100644 --- a/gfx/gl/GLScreenBuffer.h +++ b/gfx/gl/GLScreenBuffer.h @@ -56,12 +56,13 @@ class SwapChain final { public: UniquePtr mFactory; - private: - std::shared_ptr mFrontBuffer; - SwapChainPresenter* mPresenter = nullptr; - private: std::queue> mPool; + std::shared_ptr mFrontBuffer; + public: + std::shared_ptr mPrevFrontBuffer; // Hold this ref while it's in-flight. + private: + SwapChainPresenter* mPresenter = nullptr; public: SwapChain();