From 086c044dc34dfc0f74fbe41f4ecb402b2cd34884 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:33 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- gfx/layers/RemoteTextureMap.cpp | 100 +++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 47 deletions(-) (limited to 'gfx/layers/RemoteTextureMap.cpp') diff --git a/gfx/layers/RemoteTextureMap.cpp b/gfx/layers/RemoteTextureMap.cpp index fa0cfd33f5..3fe3b13deb 100644 --- a/gfx/layers/RemoteTextureMap.cpp +++ b/gfx/layers/RemoteTextureMap.cpp @@ -369,7 +369,11 @@ void RemoteTextureMap::PushTexture( aTextureId, aTextureHost, std::move(aTextureData), std::move(aResourceWrapper)); - MOZ_ASSERT(owner->mLatestTextureId < aTextureId); + MOZ_ASSERT(owner->mLatestPushedTextureId < aTextureId); + if (owner->mLatestPushedTextureId < aTextureId) { + owner->mLatestPushedTextureId = aTextureId; + } + MOZ_ASSERT(owner->mLatestUsingTextureId < aTextureId); owner->mWaitingTextureDataHolders.push_back(std::move(textureData)); @@ -898,9 +902,9 @@ void RemoteTextureMap::UpdateTexture(const MonitorAutoLock& aProofOfLock, const RemoteTextureId aTextureId) { MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread()); MOZ_ASSERT(aOwner); - MOZ_ASSERT(aTextureId >= aOwner->mLatestTextureId); + MOZ_ASSERT(aTextureId >= aOwner->mLatestUsingTextureId); - if (aTextureId == aOwner->mLatestTextureId) { + if (aTextureId == aOwner->mLatestUsingTextureId) { // No need to update texture. return; } @@ -913,7 +917,7 @@ void RemoteTextureMap::UpdateTexture(const MonitorAutoLock& aProofOfLock, } MOZ_RELEASE_ASSERT(front->mTextureHost); aOwner->mLatestTextureHost = front->mTextureHost; - aOwner->mLatestTextureId = front->mTextureId; + aOwner->mLatestUsingTextureId = front->mTextureId; UniquePtr holder = std::move(front); aOwner->mWaitingTextureDataHolders.pop_front(); @@ -962,10 +966,42 @@ void RemoteTextureMap::GetAllRenderingReadyCallbacks( MOZ_ASSERT(aOwner->mRenderingReadyCallbackHolders.empty()); } +bool RemoteTextureMap::WaitForRemoteTextureOwner( + RemoteTextureHostWrapper* aTextureHostWrapper) { + MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread()); + MOZ_ASSERT(aTextureHostWrapper); + + const auto& ownerId = aTextureHostWrapper->mOwnerId; + const auto& forPid = aTextureHostWrapper->mForPid; + + MonitorAutoLock lock(mMonitor); + + auto* owner = GetTextureOwner(lock, ownerId, forPid); + // If there is no texture owner yet, then we might need to wait for one to + // be created, if allowed. If so, we must also wait for an initial texture + // host to be created so we can use it. + if (!owner || (!owner->mLatestTextureHost && + owner->mWaitingTextureDataHolders.empty())) { + const TimeDuration timeout = TimeDuration::FromMilliseconds(10000); + while (!owner || (!owner->mLatestTextureHost && + owner->mWaitingTextureDataHolders.empty())) { + if (owner && (owner->mIsContextLost || owner->mDeferUnregister)) { + // If the context was lost, no further updates are expected. + return false; + } + CVStatus status = mMonitor.Wait(timeout); + if (status == CVStatus::Timeout) { + return false; + } + owner = GetTextureOwner(lock, ownerId, forPid); + } + } + return true; +} + bool RemoteTextureMap::GetRemoteTexture( RemoteTextureHostWrapper* aTextureHostWrapper, - std::function&& aReadyCallback, - bool aWaitForRemoteTextureOwner) { + std::function&& aReadyCallback) { MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread()); MOZ_ASSERT(aTextureHostWrapper); @@ -983,27 +1019,8 @@ bool RemoteTextureMap::GetRemoteTexture( MonitorAutoLock lock(mMonitor); auto* owner = GetTextureOwner(lock, ownerId, forPid); - // If there is no texture owner yet, then we might need to wait for one to - // be created, if allowed. If so, we must also wait for an initial texture - // host to be created so we can use it. - if (!owner || (aWaitForRemoteTextureOwner && !owner->mLatestTextureHost && - owner->mWaitingTextureDataHolders.empty())) { - if (!aWaitForRemoteTextureOwner) { - return false; - } - const TimeDuration timeout = TimeDuration::FromMilliseconds(10000); - while (!owner || (!owner->mLatestTextureHost && - owner->mWaitingTextureDataHolders.empty())) { - if (owner && (owner->mIsContextLost || owner->mDeferUnregister)) { - // If the context was lost, no further updates are expected. - return false; - } - CVStatus status = mMonitor.Wait(timeout); - if (status == CVStatus::Timeout) { - return false; - } - owner = GetTextureOwner(lock, ownerId, forPid); - } + if (!owner) { + return false; } UpdateTexture(lock, owner, textureId); @@ -1014,7 +1031,7 @@ bool RemoteTextureMap::GetRemoteTexture( return false; } - if (textureId == owner->mLatestTextureId) { + if (textureId == owner->mLatestUsingTextureId) { MOZ_ASSERT(owner->mLatestTextureHost); MOZ_ASSERT(owner->mLatestTextureHost->GetSize() == size); if (owner->mLatestTextureHost->GetSize() != size) { @@ -1034,7 +1051,7 @@ bool RemoteTextureMap::GetRemoteTexture( } // Update mRemoteTextureHost - if (textureId == owner->mLatestTextureId) { + if (textureId == owner->mLatestUsingTextureId) { const auto key = std::pair(forPid, textureId); auto it = mRemoteTextureHostWrapperHolders.find(key); if (it != mRemoteTextureHostWrapperHolders.end() && @@ -1195,16 +1212,9 @@ bool RemoteTextureMap::CheckRemoteTextureReady( return true; } - if (it->second->mRemoteTextureHost) { + if (owner->mLatestPushedTextureId >= aInfo.mTextureId) { return true; } - MOZ_ASSERT(!it->second->mRemoteTextureHost); - - // Check if RemoteTextureId is as expected. - if (!owner->mRenderingReadyCallbackHolders.empty()) { - auto& front = owner->mRenderingReadyCallbackHolders.front(); - MOZ_RELEASE_ASSERT(aInfo.mTextureId >= front->mTextureId); - } auto callbackHolder = MakeUnique( aInfo.mTextureId, std::move(aCallback)); @@ -1234,9 +1244,8 @@ bool RemoteTextureMap::WaitRemoteTextureReady(const RemoteTextureInfo& aInfo) { } const TimeDuration timeout = TimeDuration::FromMilliseconds(1000); - TextureHost* remoteTexture = it->second->mRemoteTextureHost; - while (!remoteTexture) { + while (owner->mLatestPushedTextureId < aInfo.mTextureId) { CVStatus status = mMonitor.Wait(timeout); if (status == CVStatus::Timeout) { MOZ_ASSERT_UNREACHABLE("unexpected to be called"); @@ -1251,14 +1260,11 @@ bool RemoteTextureMap::WaitRemoteTextureReady(const RemoteTextureInfo& aInfo) { return false; } - remoteTexture = it->second->mRemoteTextureHost; - if (!remoteTexture) { - auto* owner = GetTextureOwner(lock, aInfo.mOwnerId, aInfo.mForPid); - // When owner is alreay unregistered, remote texture will not be pushed. - if (!owner || owner->mIsContextLost) { - // This could happen with IPC abnormal shutdown - return false; - } + auto* owner = GetTextureOwner(lock, aInfo.mOwnerId, aInfo.mForPid); + // When owner is alreay unregistered, remote texture will not be pushed. + if (!owner || owner->mIsContextLost) { + // This could happen with IPC abnormal shutdown + return false; } } -- cgit v1.2.3