Bug 1875193 - Don't recycle SharedSurfaces from different SurfaceFactory. r=sotaro

It looks like we're accidentally putting SharedSurfaces that came from a different
SurfaceFactory back into a different one recycling. This happens because on context
loss in CanvasTranslator, the old GL context may go away, though the RemoteTextureOwnerClient
has a shared recycling bin that might accidentally keep the old surfaces.

This also tries to clear the old recycled surfaces as soon as possible on a context
loss now.

Differential Revision: https://phabricator.services.mozilla.com/D198918
This commit is contained in:
Lee Salzman 2024-01-18 06:46:51 +00:00
Родитель b9a7cef7df
Коммит 80306e69c7
4 изменённых файлов: 20 добавлений и 6 удалений

Просмотреть файл

@ -1257,10 +1257,13 @@ bool WebGLContext::PushRemoteTexture(
ownerClient->PushTexture(textureId, ownerId, keepAlive, size, surfaceFormat,
*desc);
auto recycledSurface = ownerClient->GetRecycledSharedSurface(
size, surfaceFormat, desc->type(), ownerId);
if (recycledSurface) {
swapChain.StoreRecycledSurface(recycledSurface);
// Look for a recycled surface that matches the swap chain.
while (auto recycledSurface = ownerClient->GetRecycledSharedSurface(
size, surfaceFormat, desc->type(), ownerId)) {
if (swapChain.StoreRecycledSurface(recycledSurface)) {
break;
}
}
return true;
}

Просмотреть файл

@ -75,9 +75,16 @@ void SwapChain::ClearPool() {
mPrevFrontBuffer = nullptr;
}
void SwapChain::StoreRecycledSurface(
bool SwapChain::StoreRecycledSurface(
const std::shared_ptr<SharedSurface>& surf) {
MOZ_ASSERT(mFactory);
if (!mFactory || NS_WARN_IF(surf->mDesc.gl != mFactory->mDesc.gl)) {
// Ensure we don't accidentally store an expired shared surface or from a
// different context.
return false;
}
mPool.push(surf);
return true;
}
// -

Просмотреть файл

@ -71,7 +71,7 @@ class SwapChain final {
virtual ~SwapChain();
void ClearPool();
void StoreRecycledSurface(const std::shared_ptr<SharedSurface>& surf);
bool StoreRecycledSurface(const std::shared_ptr<SharedSurface>& surf);
const auto& FrontBuffer() const { return mFrontBuffer; }
UniquePtr<SwapChainPresenter> Acquire(const gfx::IntSize&, gfx::ColorSpace2);

Просмотреть файл

@ -114,6 +114,10 @@ bool CanvasTranslator::EnsureSharedContextWebgl() {
if (!mSharedContext || mSharedContext->IsContextLost()) {
if (mSharedContext) {
ForceDrawTargetWebglFallback();
if (mRemoteTextureOwner) {
// Ensure any shared surfaces referring to the old context go away.
mRemoteTextureOwner->ClearRecycledTextures();
}
}
mSharedContext = gfx::SharedContextWebgl::Create();
if (!mSharedContext || mSharedContext->IsContextLost()) {