Bug 1699224 - Part 3. Complete shutdown of SharedSurfacesParent on the main thread. r=jrmuizel

We want to use nsExpirationTracker to decide when we should unmap shared
surfaces from our address space. This relies upon the observer service
and we need to be both initialized and shutdown on the main thread to
add/remove the observer. SharedSurfacesParent is already initialized on
the main thread, and we just need to complete shutdown on the main
thread.

Differential Revision: https://phabricator.services.mozilla.com/D109439
This commit is contained in:
Andrew Osmond 2021-03-26 18:21:15 +00:00
Родитель a4cbd54fb5
Коммит a5c6568905
3 изменённых файлов: 22 добавлений и 13 удалений

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

@ -25,15 +25,6 @@ StaticAutoPtr<SharedSurfacesParent> SharedSurfacesParent::sInstance;
SharedSurfacesParent::SharedSurfacesParent() = default;
SharedSurfacesParent::~SharedSurfacesParent() {
for (const auto& key : mSurfaces.Keys()) {
// There may be lingering consumers of the surfaces that didn't get shutdown
// yet but since we are here, we know the render thread is finished and we
// can unregister everything.
wr::RenderThread::Get()->UnregisterExternalImageDuringShutdown(key);
}
}
/* static */
void SharedSurfacesParent::Initialize() {
MOZ_ASSERT(NS_IsMainThread());
@ -44,11 +35,28 @@ void SharedSurfacesParent::Initialize() {
}
/* static */
void SharedSurfacesParent::Shutdown() {
void SharedSurfacesParent::ShutdownRenderThread() {
// The main thread should blocked on waiting for the render thread to
// complete so this should be safe to release off the main thread.
MOZ_ASSERT(wr::RenderThread::IsInRenderThread());
StaticMutexAutoLock lock(sMutex);
MOZ_ASSERT(sInstance);
for (const auto& key : mSurfaces.Keys()) {
// There may be lingering consumers of the surfaces that didn't get shutdown
// yet but since we are here, we know the render thread is finished and we
// can unregister everything.
wr::RenderThread::Get()->UnregisterExternalImageDuringShutdown(key);
}
}
/* static */
void SharedSurfacesParent::Shutdown() {
// The compositor thread and render threads are shutdown, so this is the last
// thread that could use it. The expiration tracker needs to be freed on the
// main thread.
MOZ_ASSERT(NS_IsMainThread());
StaticMutexAutoLock lock(sMutex);
sInstance = nullptr;
}

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

@ -34,6 +34,7 @@ class SharedSurfacesMemoryReport;
class SharedSurfacesParent final {
public:
static void Initialize();
static void ShutdownRenderThread();
static void Shutdown();
// Get without increasing the consumer count.
@ -58,8 +59,6 @@ class SharedSurfacesParent final {
static bool AccumulateMemoryReport(SharedSurfacesMemoryReport& aReport);
~SharedSurfacesParent();
private:
friend class SharedSurfacesChild;

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

@ -120,6 +120,8 @@ void RenderThread::ShutDown() {
sRenderThread->Loop()->PostTask(runnable.forget());
task.Wait();
layers::SharedSurfacesParent::Shutdown();
sRenderThread = nullptr;
#ifdef XP_WIN
if (widget::WinCompositorWindowThread::Get()) {
@ -140,7 +142,7 @@ void RenderThread::ShutDownTask(layers::SynchronousTask* aTask) {
// Releasing on the render thread will allow us to avoid dispatching to remove
// remaining textures from the texture map.
layers::SharedSurfacesParent::Shutdown();
layers::SharedSurfacesParent::ShutdownRenderThread();
ClearAllBlobImageResources();
ClearSingletonGL();