Bug 1789658 - Keep gl::SharedSurface/TextureData alive if remote texture's TextureHost is still in use by WebRender r=lsalzman

Differential Revision: https://phabricator.services.mozilla.com/D156774
This commit is contained in:
sotaro 2022-09-08 14:27:44 +00:00
Родитель 7d8e214183
Коммит ee73cfe360
2 изменённых файлов: 42 добавлений и 4 удалений

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

@ -154,14 +154,14 @@ void RemoteTextureMap::PushTexture(
if (front->mTextureData && front->mTextureData->AsBufferTextureData()) {
owner->mRecycledTextures.push(std::move(front->mTextureData));
}
owner->mUsingTextureDataHolders.pop();
owner->mUsingTextureDataHolders.pop_front();
} else if (front->mTextureHost &&
front->mTextureHost->NumCompositableRefs() >= 0) {
// Remote texture is still in use by WebRender.
break;
} else {
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
owner->mUsingTextureDataHolders.pop();
owner->mUsingTextureDataHolders.pop_front();
}
}
}
@ -181,6 +181,31 @@ void RemoteTextureMap::RegisterTextureOwner(const RemoteTextureOwnerId aOwnerId,
mTextureOwners.emplace(key, std::move(owner));
}
void RemoteTextureMap::KeepTextureDataAliveForTextureHostIfNecessary(
const MutexAutoLock& aProofOfLock,
std::deque<UniquePtr<TextureDataHolder>>& aHolders) {
for (auto& holder : aHolders) {
// If remote texture of TextureHost still exist, keep
// gl::SharedSurface/TextureData alive while the TextureHost is alive.
if (holder->mTextureHost &&
holder->mTextureHost->NumCompositableRefs() >= 0) {
RefPtr<nsISerialEventTarget> eventTarget =
MessageLoop::current()->SerialEventTarget();
RefPtr<Runnable> runnable = NS_NewRunnableFunction(
"RemoteTextureMap::UnregisterTextureOwner::Runnable",
[data = std::move(holder->mTextureData),
surface = std::move(holder->mSharedSurface)]() {});
auto destroyedCallback = [eventTarget = std::move(eventTarget),
runnable = std::move(runnable)]() mutable {
eventTarget->Dispatch(runnable.forget());
};
holder->mTextureHost->SetDestroyedCallback(destroyedCallback);
}
}
}
void RemoteTextureMap::UnregisterTextureOwner(
const RemoteTextureOwnerId aOwnerId, const base::ProcessId aForPid) {
UniquePtr<TextureOwner> releasingOwner; // Release outside the mutex
@ -193,6 +218,10 @@ void RemoteTextureMap::UnregisterTextureOwner(
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
return;
}
KeepTextureDataAliveForTextureHostIfNecessary(
lock, it->second->mUsingTextureDataHolders);
releasingOwner = std::move(it->second);
mTextureOwners.erase(it);
}
@ -214,6 +243,10 @@ void RemoteTextureMap::UnregisterTextureOwners(
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
continue;
}
KeepTextureDataAliveForTextureHostIfNecessary(
lock, it->second->mUsingTextureDataHolders);
releasingOwners.push_back(std::move(it->second));
mTextureOwners.erase(it);
}
@ -268,7 +301,7 @@ void RemoteTextureMap::UpdateTexture(const MutexAutoLock& aProofOfLock,
UniquePtr<TextureDataHolder> holder = std::move(front);
aOwner->mWaitingTextureDataHolders.pop();
aOwner->mUsingTextureDataHolders.push(std::move(holder));
aOwner->mUsingTextureDataHolders.push_back(std::move(holder));
}
}

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

@ -7,6 +7,7 @@
#ifndef MOZILLA_GFX_RemoteTextureMap_H
#define MOZILLA_GFX_RemoteTextureMap_H
#include <deque>
#include <functional>
#include <map>
#include <memory>
@ -148,7 +149,7 @@ class RemoteTextureMap {
// Holds TextureDataHolders that wait to be used by WebRender.
std::queue<UniquePtr<TextureDataHolder>> mWaitingTextureDataHolders;
// Holds TextureDataHolders that are used by WebRender
std::queue<UniquePtr<TextureDataHolder>> mUsingTextureDataHolders;
std::deque<UniquePtr<TextureDataHolder>> mUsingTextureDataHolders;
RemoteTextureId mLatestTextureId = {0};
CompositableTextureHostRef mLatestTextureHost;
std::stack<UniquePtr<TextureData>> mRecycledTextures;
@ -159,6 +160,10 @@ class RemoteTextureMap {
RemoteTextureMap::TextureOwner* aOwner,
const RemoteTextureId aTextureId);
void KeepTextureDataAliveForTextureHostIfNecessary(
const MutexAutoLock& aProofOfLock,
std::deque<UniquePtr<TextureDataHolder>>& aHolders);
RemoteTextureMap::TextureOwner* GetTextureOwner(
const MutexAutoLock& aProofOfLock, const RemoteTextureOwnerId aOwnerId,
const base::ProcessId aForPid);