tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 9858dfd5c9408a4a02bac409b5b46967256dffd9
parent 6512de7a7f6b516881ba5940ca38b40436c47575
Author: Andy Leiserson <aleiserson@mozilla.com>
Date:   Tue,  7 Oct 2025 20:32:49 +0000

Bug 1958017 - Synchronize MacIOSurface presentation with rendering r=sotaro,mstange,ahale

Differential Revision: https://phabricator.services.mozilla.com/D265715

Diffstat:
Mgfx/webrender_bindings/RenderCompositorNative.cpp | 14++++++++++++++
Mgfx/webrender_bindings/RenderCompositorNative.h | 3+++
Mgfx/webrender_bindings/RenderMacIOSurfaceTextureHost.cpp | 17+++++++++++++++++
3 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/gfx/webrender_bindings/RenderCompositorNative.cpp b/gfx/webrender_bindings/RenderCompositorNative.cpp @@ -18,6 +18,7 @@ #include "mozilla/layers/ProfilerScreenshots.h" #include "mozilla/layers/SurfacePool.h" #include "mozilla/StaticPrefs_gfx.h" +#include "mozilla/webrender/RenderTextureHost.h" #include "mozilla/webrender/RenderThread.h" #include "mozilla/widget/CompositorWidget.h" #include "RenderCompositorRecordedFrame.h" @@ -355,6 +356,19 @@ void RenderCompositorNative::AttachExternalImage( surface.mNativeLayers.begin()->second->AttachExternalImage(image); } +void RenderCompositorNativeOGL::AttachExternalImage( + wr::NativeSurfaceId aId, wr::ExternalImageId aExternalImage) { + RenderTextureHost* image = + RenderThread::Get()->GetRenderTexture(aExternalImage); + + // image->Lock only uses the channel index to populate the returned + // `WrExternalImage`. Since we don't use that, it doesn't matter + // what channel index we pass. + image->Lock(0, mGL); + + RenderCompositorNative::AttachExternalImage(aId, aExternalImage); +} + void RenderCompositorNative::DestroySurface(NativeSurfaceId aId) { auto surfaceCursor = mSurfaces.find(aId); MOZ_RELEASE_ASSERT(surfaceCursor != mSurfaces.end()); diff --git a/gfx/webrender_bindings/RenderCompositorNative.h b/gfx/webrender_bindings/RenderCompositorNative.h @@ -172,6 +172,9 @@ class RenderCompositorNativeOGL : public RenderCompositorNative { wr::DeviceIntRect aValidRect) override; void Unbind() override; + void AttachExternalImage(wr::NativeSurfaceId aId, + wr::ExternalImageId aExternalImage) override; + protected: void InsertFrameDoneSync(); diff --git a/gfx/webrender_bindings/RenderMacIOSurfaceTextureHost.cpp b/gfx/webrender_bindings/RenderMacIOSurfaceTextureHost.cpp @@ -14,6 +14,9 @@ #include "mozilla/gfx/Logging.h" #include "mozilla/layers/GpuFence.h" +#include "mozilla/ProfilerLabels.h" +#include "mozilla/ProfilerMarkers.h" +#include "mozilla/TimeStamp.h" #include "ScopedGLHelpers.h" namespace mozilla { @@ -106,6 +109,20 @@ wr::WrExternalImage RenderMacIOSurfaceTextureHost::Lock(uint8_t aChannelIndex, } } + if (mGpuFence) { + // This timeout matches the acquisition timeout for the keyed mutex + // in the D3D11 texture host. + auto timeout = TimeDuration::FromMilliseconds(10000); + auto start = TimeStamp::Now(); + AUTO_PROFILER_TRACING_MARKER("WebRender", "Lock MacIOSurfaceTexture", + GRAPHICS); + while (!mGpuFence->HasCompleted() && (TimeStamp::Now() - start) < timeout) { + PR_Sleep(PR_MillisecondsToInterval(1)); + } + } else { + PROFILER_MARKER_UNTYPED("No GpuFence", GRAPHICS); + } + const auto size = GetSize(aChannelIndex); return NativeTextureToWrExternalImage(GetGLHandle(aChannelIndex), 0.0, 0.0, static_cast<float>(size.width),