Bug 1869931 - Remove RemoteTexture push callback r=gfx-reviewers,lsalzman

WebGPU rendering needs to be synchronized to dom like WebGL and canvas 2D. But the current rendering is not synchronized to dom.

Differential Revision: https://phabricator.services.mozilla.com/D197326
This commit is contained in:
sotaro 2024-01-23 17:17:01 +00:00
parent 5b7599f8a7
commit 6f9048f788
14 changed files with 8 additions and 224 deletions

View file

@ -228,8 +228,7 @@ bool CanvasContext::UpdateWebRenderCanvasData(
auto* renderer = aCanvasData->GetCanvasRenderer();
if (renderer && mRemoteTextureOwnerId.isSome() &&
renderer->GetRemoteTextureOwnerIdOfPushCallback() ==
mRemoteTextureOwnerId) {
renderer->GetRemoteTextureOwnerId() == mRemoteTextureOwnerId) {
return true;
}
@ -252,7 +251,7 @@ bool CanvasContext::InitializeCanvasRenderer(
data.mContext = this;
data.mSize = mCanvasSize;
data.mIsOpaque = false;
data.mRemoteTextureOwnerIdOfPushCallback = mRemoteTextureOwnerId;
data.mRemoteTextureOwnerId = mRemoteTextureOwnerId;
aRenderer->Initialize(data);
aRenderer->SetDirty();

View file

@ -48,7 +48,7 @@ struct CanvasRendererData final {
gl::OriginPos mOriginPos = gl::OriginPos::TopLeft;
// Used in remote texture push callback
Maybe<RemoteTextureOwnerId> mRemoteTextureOwnerIdOfPushCallback = Nothing();
Maybe<RemoteTextureOwnerId> mRemoteTextureOwnerId = Nothing();
nsICanvasRenderingContextInternal* GetContext() const {
return mContext.get();
@ -126,8 +126,8 @@ class CanvasRenderer : public RefCounted<CanvasRenderer> {
const gfx::IntSize& GetSize() const { return mData.mSize; }
bool IsOpaque() const { return mData.mIsOpaque; }
bool YIsDown() const { return mData.mOriginPos == gl::OriginPos::TopLeft; }
Maybe<RemoteTextureOwnerId> GetRemoteTextureOwnerIdOfPushCallback() {
return mData.mRemoteTextureOwnerIdOfPushCallback;
Maybe<RemoteTextureOwnerId> GetRemoteTextureOwnerId() {
return mData.mRemoteTextureOwnerId;
}
void SetDirty() { mDirty = true; }

View file

@ -354,19 +354,6 @@ void RemoteTextureMap::PushTexture(
gfxCriticalNoteOnce << "Texture pushed during context lost";
}
const auto key = std::pair(aForPid, aOwnerId);
auto it = mRemoteTexturePushListeners.find(key);
// Notify a new texture if callback is requested
if (it != mRemoteTexturePushListeners.end()) {
RefPtr<CompositableHost> compositableHost = it->second;
RefPtr<Runnable> runnable = NS_NewRunnableFunction(
"RemoteTextureMap::PushTexture::Runnable",
[compositableHost, aTextureId, aOwnerId, aForPid]() {
compositableHost->NotifyPushTexture(aTextureId, aOwnerId, aForPid);
});
CompositorThread()->Dispatch(runnable.forget());
}
auto textureData = MakeUnique<TextureDataHolder>(
aTextureId, aTextureHost, std::move(aTextureData),
std::move(aResourceWrapper));
@ -1153,74 +1140,6 @@ void RemoteTextureMap::UnregisterRemoteTextureHostWrapper(
}
}
void RemoteTextureMap::RegisterRemoteTexturePushListener(
const RemoteTextureOwnerId aOwnerId, const base::ProcessId aForPid,
CompositableHost* aListener) {
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RefPtr<CompositableHost>
releasingCompositableHost; // Release outside the monitor
{
MonitorAutoLock lock(mMonitor);
const auto key = std::pair(aForPid, aOwnerId);
auto it = mRemoteTexturePushListeners.find(key);
// Remove obsoleted CompositableHost.
if (it != mRemoteTexturePushListeners.end()) {
releasingCompositableHost = std::move(it->second);
mRemoteTexturePushListeners.erase(it);
}
mRemoteTexturePushListeners.emplace(key, aListener);
auto* owner = GetTextureOwner(lock, aOwnerId, aForPid);
if (!owner) {
return;
}
if (owner->mWaitingTextureDataHolders.empty() &&
!owner->mLatestTextureHost) {
return;
}
// Get latest RemoteTextureId.
auto textureId = !owner->mWaitingTextureDataHolders.empty()
? owner->mWaitingTextureDataHolders.back()->mTextureId
: owner->mLatestTextureId;
// Notify the RemoteTextureId to callback
RefPtr<CompositableHost> compositableHost = aListener;
RefPtr<Runnable> runnable = NS_NewRunnableFunction(
"RemoteTextureMap::RegisterRemoteTexturePushListener::Runnable",
[compositableHost, textureId, aOwnerId, aForPid]() {
compositableHost->NotifyPushTexture(textureId, aOwnerId, aForPid);
});
CompositorThread()->Dispatch(runnable.forget());
}
}
void RemoteTextureMap::UnregisterRemoteTexturePushListener(
const RemoteTextureOwnerId aOwnerId, const base::ProcessId aForPid,
CompositableHost* aListener) {
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RefPtr<CompositableHost>
releasingCompositableHost; // Release outside the monitor
{
MonitorAutoLock lock(mMonitor);
const auto key = std::pair(aForPid, aOwnerId);
auto it = mRemoteTexturePushListeners.find(key);
if (it == mRemoteTexturePushListeners.end()) {
return;
}
if (aListener != it->second) {
// aListener was alredy obsoleted.
return;
}
releasingCompositableHost = std::move(it->second);
mRemoteTexturePushListeners.erase(it);
}
}
bool RemoteTextureMap::CheckRemoteTextureReady(
const RemoteTextureInfo& aInfo,
std::function<void(const RemoteTextureInfo&)>&& aCallback) {

View file

@ -325,14 +325,6 @@ class RemoteTextureMap {
const RemoteTextureOwnerId aOwnerId,
const base::ProcessId aForPid);
void RegisterRemoteTexturePushListener(const RemoteTextureOwnerId aOwnerId,
const base::ProcessId aForPid,
CompositableHost* aListener);
void UnregisterRemoteTexturePushListener(const RemoteTextureOwnerId aOwnerId,
const base::ProcessId aForPid,
CompositableHost* aListener);
bool CheckRemoteTextureReady(
const RemoteTextureInfo& aInfo,
std::function<void(const RemoteTextureInfo&)>&& aCallback);
@ -479,10 +471,6 @@ class RemoteTextureMap {
UniquePtr<RemoteTextureHostWrapperHolder>>
mRemoteTextureHostWrapperHolders;
std::map<std::pair<base::ProcessId, RemoteTextureOwnerId>,
RefPtr<CompositableHost>>
mRemoteTexturePushListeners;
std::map<std::pair<base::ProcessId, RemoteTextureTxnType>,
RemoteTextureTxnScheduler*>
mTxnSchedulers;

View file

@ -107,20 +107,6 @@ void ShareableCanvasRenderer::UpdateCompositableClient() {
flags |= TextureFlags::IS_OPAQUE;
}
// With remote texture push callback, a new pushed remote texture is notifiled
// from RemoteTextureMap to WebRenderImageHost.
if (mData.mRemoteTextureOwnerIdOfPushCallback) {
if (!HasPipeline()) {
GetForwarder()->EnableRemoteTexturePushCallback(
mCanvasClient, *mData.mRemoteTextureOwnerIdOfPushCallback,
mData.mSize, flags);
EnsurePipeline();
}
// Post front buffer
context->GetFrontBuffer(nullptr);
return;
}
// -
const auto fnGetExistingTc =
@ -193,7 +179,8 @@ void ShareableCanvasRenderer::UpdateCompositableClient() {
if (!mData.mIsAlphaPremult) {
flags |= TextureFlags::NON_PREMULTIPLIED;
}
if (provider && provider->WaitForRemoteTextureOwner()) {
if ((provider && provider->WaitForRemoteTextureOwner()) ||
mData.mRemoteTextureOwnerId.isSome()) {
flags |= TextureFlags::WAIT_FOR_REMOTE_TEXTURE_OWNER;
}
EnsurePipeline();

View file

@ -88,15 +88,6 @@ class CompositableHost {
virtual void UseTextureHost(const nsTArray<TimedTexture>& aTextures);
virtual void RemoveTextureHost(TextureHost* aTexture);
// Enable remote texture push callback
virtual void EnableRemoteTexturePushCallback(
const RemoteTextureOwnerId aOwnerId, const base::ProcessId aForPid,
const gfx::IntSize aSize, const TextureFlags aFlags) = 0;
// Called from RemoteTextureMap when a new remote texture is pushed
virtual void NotifyPushTexture(const RemoteTextureId aTextureId,
const RemoteTextureOwnerId aOwnerId,
const base::ProcessId aForPid) = 0;
uint64_t GetCompositorBridgeID() const { return mCompositorBridgeID; }
const AsyncCompositableRef& GetAsyncRef() const { return mAsyncRef; }

View file

@ -117,10 +117,6 @@ class CompositableForwarder : public KnowsCompositor {
const gfx::IntSize aSize,
const TextureFlags aFlags) = 0;
virtual void EnableRemoteTexturePushCallback(
CompositableClient* aCompositable, const RemoteTextureOwnerId aOwnerId,
const gfx::IntSize aSize, const TextureFlags aFlags) = 0;
void UpdateFwdTransactionId() {
++GetFwdTransactionCounter().mFwdTransactionId;
}

View file

@ -95,16 +95,6 @@ bool CompositableParentManager::ReceiveCompositableUpdate(
host->UseRemoteTexture();
break;
}
case CompositableOperationDetail::TOpEnableRemoteTexturePushCallback: {
const OpEnableRemoteTexturePushCallback& op =
aDetail.get_OpEnableRemoteTexturePushCallback();
aCompositable->SetAsyncRef(
AsyncCompositableRef(GetChildProcessId(), aHandle));
aCompositable->EnableRemoteTexturePushCallback(
op.ownerId(), GetChildProcessId(), op.size(), op.textureFlags());
break;
}
default: {
MOZ_ASSERT(false, "bad type");
}

View file

@ -133,18 +133,6 @@ void ImageBridgeChild::UseRemoteTexture(CompositableClient* aCompositable,
OpUseRemoteTexture(aTextureId, aOwnerId, aSize, aFlags)));
}
void ImageBridgeChild::EnableRemoteTexturePushCallback(
CompositableClient* aCompositable, const RemoteTextureOwnerId aOwnerId,
const gfx::IntSize aSize, const TextureFlags aFlags) {
MOZ_ASSERT(aCompositable);
MOZ_ASSERT(aCompositable->GetIPCHandle());
MOZ_ASSERT(aCompositable->IsConnected());
mTxn->AddNoSwapEdit(CompositableOperation(
aCompositable->GetIPCHandle(),
OpEnableRemoteTexturePushCallback(aOwnerId, aSize, aFlags)));
}
void ImageBridgeChild::HoldUntilCompositableRefReleasedIfNecessary(
TextureClient* aClient) {
if (!aClient) {

View file

@ -254,11 +254,6 @@ class ImageBridgeChild final : public PImageBridgeChild,
const gfx::IntSize aSize,
const TextureFlags aFlags) override;
void EnableRemoteTexturePushCallback(CompositableClient* aCompositable,
const RemoteTextureOwnerId aOwnerId,
const gfx::IntSize aSize,
const TextureFlags aFlags) override;
void ReleaseCompositable(const CompositableHandle& aHandle) override;
void ForgetImageContainer(const CompositableHandle& aHandle);

View file

@ -452,14 +452,6 @@ void WebRenderBridgeChild::UseRemoteTexture(CompositableClient* aCompositable,
OpUseRemoteTexture(aTextureId, aOwnerId, aSize, aFlags)));
}
void WebRenderBridgeChild::EnableRemoteTexturePushCallback(
CompositableClient* aCompositable, const RemoteTextureOwnerId aOwnerId,
const gfx::IntSize aSize, const TextureFlags aFlags) {
AddWebRenderParentCommand(CompositableOperation(
aCompositable->GetIPCHandle(),
OpEnableRemoteTexturePushCallback(aOwnerId, aSize, aFlags)));
}
FwdTransactionCounter& WebRenderBridgeChild::GetFwdTransactionCounter() {
return GetCompositorBridgeChild()->GetFwdTransactionCounter();
}

View file

@ -202,10 +202,6 @@ class WebRenderBridgeChild final : public PWebRenderBridgeChild,
const RemoteTextureOwnerId aOwnerId,
const gfx::IntSize aSize,
const TextureFlags aFlags) override;
void EnableRemoteTexturePushCallback(CompositableClient* aCompositable,
const RemoteTextureOwnerId aOwnerId,
const gfx::IntSize aSize,
const TextureFlags aFlags) override;
FwdTransactionCounter& GetFwdTransactionCounter() override;
bool InForwarderThread() override;

View file

@ -46,13 +46,6 @@ WebRenderImageHost::~WebRenderImageHost() {
}
void WebRenderImageHost::OnReleased() {
if (mRemoteTextureOwnerIdOfPushCallback) {
RemoteTextureMap::Get()->UnregisterRemoteTexturePushListener(
*mRemoteTextureOwnerIdOfPushCallback, mForPidOfPushCallback, this);
mRemoteTextureOwnerIdOfPushCallback = Nothing();
mSizeOfPushCallback = gfx::IntSize();
mFlagsOfPushCallback = TextureFlags::NO_FLAGS;
}
if (!mPendingRemoteTextureWrappers.empty()) {
mPendingRemoteTextureWrappers.clear();
}
@ -165,8 +158,7 @@ void WebRenderImageHost::UseRemoteTexture() {
return;
}
const bool useReadyCallback =
GetAsyncRef() && mRemoteTextureOwnerIdOfPushCallback.isNothing();
const bool useReadyCallback = bool(GetAsyncRef());
CompositableTextureHostRef texture;
if (useReadyCallback) {
@ -246,41 +238,6 @@ void WebRenderImageHost::UseRemoteTexture() {
}
}
void WebRenderImageHost::EnableRemoteTexturePushCallback(
const RemoteTextureOwnerId aOwnerId, const base::ProcessId aForPid,
const gfx::IntSize aSize, const TextureFlags aFlags) {
if (!GetAsyncRef()) {
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
return;
}
if (mRemoteTextureOwnerIdOfPushCallback.isSome()) {
RemoteTextureMap::Get()->UnregisterRemoteTexturePushListener(aOwnerId,
aForPid, this);
}
RemoteTextureMap::Get()->RegisterRemoteTexturePushListener(aOwnerId, aForPid,
this);
mRemoteTextureOwnerIdOfPushCallback = Some(aOwnerId);
mForPidOfPushCallback = aForPid;
mSizeOfPushCallback = aSize;
mFlagsOfPushCallback = aFlags;
}
void WebRenderImageHost::NotifyPushTexture(const RemoteTextureId aTextureId,
const RemoteTextureOwnerId aOwnerId,
const base::ProcessId aForPid) {
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
if (mRemoteTextureOwnerIdOfPushCallback != Some(aOwnerId)) {
// RemoteTextureOwnerId is already obsoleted
return;
}
PushPendingRemoteTexture(aTextureId, aOwnerId, aForPid, mSizeOfPushCallback,
mFlagsOfPushCallback);
UseRemoteTexture();
}
void WebRenderImageHost::CleanupResources() {
ClearImages();
SetCurrentTextureHost(nullptr);

View file

@ -33,15 +33,6 @@ class WebRenderImageHost : public CompositableHost, public ImageComposite {
void UseTextureHost(const nsTArray<TimedTexture>& aTextures) override;
void RemoveTextureHost(TextureHost* aTexture) override;
void EnableRemoteTexturePushCallback(const RemoteTextureOwnerId aOwnerId,
const base::ProcessId aForPid,
const gfx::IntSize aSize,
const TextureFlags aFlags) override;
void NotifyPushTexture(const RemoteTextureId aTextureId,
const RemoteTextureOwnerId aOwnerId,
const base::ProcessId aForPid) override;
void Dump(std::stringstream& aStream, const char* aPrefix = "",
bool aDumpHtml = false) override;
@ -90,11 +81,6 @@ class WebRenderImageHost : public CompositableHost, public ImageComposite {
bool mWaitingReadyCallback = false;
bool mWaitForRemoteTextureOwner = true;
Maybe<RemoteTextureOwnerId> mRemoteTextureOwnerIdOfPushCallback;
base::ProcessId mForPidOfPushCallback;
gfx::IntSize mSizeOfPushCallback;
TextureFlags mFlagsOfPushCallback = TextureFlags::NO_FLAGS;
#if XP_WIN
RefPtr<TextureWrapperD3D11Allocator> mTextureAllocator;
#endif