Files
tubestation/gfx/layers/ipc/CompositableInProcessManager.cpp
Andrew Osmond 16bded8b81 Bug 1754978 - Part 1. Refactor CompositableHandle infrastructure to allow in-process driven handles. r=sotaro
For WebGPU, we produce the textures in the compositor process and the
content process doesn't need to be that involved except for hooking up
the texture to the display list. Currently this is done via an external
image ID.

Given that WebGPU needs to work with OffscreenCanvas, it would be best
if its display pipeline was consistent whether it was gotten from an
HTMLCanvasElement, OffscreenCanvas on the main thread, or on a worker
thread. As such, using an AsyncImagePipeline would be best.

However there is no real need to bounce the handles across process
boundaries. Hence this patch which adds CompositableInProcessManager.
This static class is responsible for collecting WebRenderImageHost
objects backed by TextureHost objects which do not leave the compositor
process. This will allow WebGPUParent to schedule compositions directly
in future patches.

Differential Revision: https://phabricator.services.mozilla.com/D138588
2022-02-18 15:59:12 +00:00

77 lines
2.4 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "CompositableInProcessManager.h"
#include "mozilla/layers/CompositorThread.h"
namespace mozilla::layers {
std::map<std::pair<base::ProcessId, uint64_t>, RefPtr<WebRenderImageHost>>
CompositableInProcessManager::sCompositables;
StaticMutex CompositableInProcessManager::sMutex;
uint32_t CompositableInProcessManager::sNamespace(0);
Atomic<uint32_t> CompositableInProcessManager::sNextResourceId(1);
Atomic<uint64_t> CompositableInProcessManager::sNextHandle(1);
/* static */ void CompositableInProcessManager::Initialize(
uint32_t aNamespace) {
MOZ_ASSERT(NS_IsMainThread());
sNamespace = aNamespace;
}
/* static */ void CompositableInProcessManager::Shutdown() {
MOZ_ASSERT(NS_IsMainThread());
StaticMutexAutoLock lock(sMutex);
sCompositables.clear();
}
/* static */ RefPtr<WebRenderImageHost> CompositableInProcessManager::Add(
const CompositableHandle& aHandle, base::ProcessId aForPid,
const TextureInfo& aTextureInfo) {
MOZ_RELEASE_ASSERT(aHandle.Value());
StaticMutexAutoLock lock(sMutex);
const auto key = std::pair(aForPid, aHandle.Value());
if (sCompositables.find(key) != sCompositables.end()) {
MOZ_ASSERT_UNREACHABLE("Duplicate handle!");
return nullptr;
}
auto host = MakeRefPtr<WebRenderImageHost>(aTextureInfo);
sCompositables[key] = host;
host->SetAsyncRef(AsyncCompositableRef(aForPid, aHandle));
return host;
}
/* static */ RefPtr<WebRenderImageHost> CompositableInProcessManager::Find(
const CompositableHandle& aHandle, base::ProcessId aForPid) {
StaticMutexAutoLock lock(sMutex);
const auto key = std::pair(aForPid, aHandle.Value());
const auto i = sCompositables.find(key);
if (NS_WARN_IF(i == sCompositables.end())) {
return nullptr;
}
return i->second;
}
/* static */ void CompositableInProcessManager::Release(
const CompositableHandle& aHandle, base::ProcessId aForPid) {
StaticMutexAutoLock lock(sMutex);
const auto key = std::pair(aForPid, aHandle.Value());
const auto i = sCompositables.find(key);
if (NS_WARN_IF(i == sCompositables.end())) {
return;
}
sCompositables.erase(i);
}
} // namespace mozilla::layers