From ebbda1906f229f33b40e0267eb2c7e51bbccb443 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Sat, 5 Aug 2023 01:05:47 +0000 Subject: [PATCH] Bug 1847244 - Finish plumbing will-read-frequently through WindowRenderer. r=jrmuizel Differential Revision: https://phabricator.services.mozilla.com/D185451 --- dom/canvas/CanvasRenderingContext2D.cpp | 5 +++-- gfx/layers/wr/WebRenderLayerManager.cpp | 12 ++++++++---- gfx/layers/wr/WebRenderLayerManager.h | 3 ++- layout/painting/WindowRenderer.cpp | 13 +++++++++---- layout/painting/WindowRenderer.h | 3 ++- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index 2880511f59f8..ea396a41573f 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -1683,8 +1683,9 @@ bool CanvasRenderingContext2D::TrySharedTarget( return false; } - aOutProvider = - renderer->CreatePersistentBufferProvider(GetSize(), GetSurfaceFormat()); + aOutProvider = renderer->CreatePersistentBufferProvider( + GetSize(), GetSurfaceFormat(), + !mAllowAcceleration || mWillReadFrequently); if (!aOutProvider) { return false; diff --git a/gfx/layers/wr/WebRenderLayerManager.cpp b/gfx/layers/wr/WebRenderLayerManager.cpp index 6ea61b23b648..779c633c0b5a 100644 --- a/gfx/layers/wr/WebRenderLayerManager.cpp +++ b/gfx/layers/wr/WebRenderLayerManager.cpp @@ -749,8 +749,12 @@ void WebRenderLayerManager::ScheduleComposite(wr::RenderReasons aReasons) { already_AddRefed WebRenderLayerManager::CreatePersistentBufferProvider( - const gfx::IntSize& aSize, gfx::SurfaceFormat aFormat) { - if (!gfxPlatform::UseRemoteCanvas()) { + const gfx::IntSize& aSize, gfx::SurfaceFormat aFormat, + bool aWillReadFrequently) { + // Only initialize devices if hardware acceleration may possibly be used. + // Remoting moves hardware usage out-of-process, while will-read-frequently + // avoids hardware acceleration entirely. + if (!aWillReadFrequently && !gfxPlatform::UseRemoteCanvas()) { #ifdef XP_WIN // Any kind of hardware acceleration is incompatible with Win32k Lockdown // We don't initialize devices here so that PersistentBufferProviderShared @@ -765,8 +769,8 @@ WebRenderLayerManager::CreatePersistentBufferProvider( } RefPtr provider = - PersistentBufferProviderShared::Create(aSize, aFormat, - AsKnowsCompositor()); + PersistentBufferProviderShared::Create( + aSize, aFormat, AsKnowsCompositor(), aWillReadFrequently); if (provider) { return provider.forget(); } diff --git a/gfx/layers/wr/WebRenderLayerManager.h b/gfx/layers/wr/WebRenderLayerManager.h index e9809ea2236e..f6d73f895d25 100644 --- a/gfx/layers/wr/WebRenderLayerManager.h +++ b/gfx/layers/wr/WebRenderLayerManager.h @@ -125,7 +125,8 @@ class WebRenderLayerManager final : public WindowRenderer { void SetFocusTarget(const FocusTarget& aFocusTarget); already_AddRefed CreatePersistentBufferProvider( - const gfx::IntSize& aSize, gfx::SurfaceFormat aFormat) override; + const gfx::IntSize& aSize, gfx::SurfaceFormat aFormat, + bool aWillReadFrequently) override; bool AsyncPanZoomEnabled() const; diff --git a/layout/painting/WindowRenderer.cpp b/layout/painting/WindowRenderer.cpp index d695ef8ebae4..942e8564b2f6 100644 --- a/layout/painting/WindowRenderer.cpp +++ b/layout/painting/WindowRenderer.cpp @@ -117,13 +117,18 @@ void FrameRecorder::StopFrameTimeRecording(uint32_t aStartIndex, already_AddRefed WindowRenderer::CreatePersistentBufferProvider( - const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat) { + const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat, + bool aWillReadFrequently) { RefPtr bufferProvider; // If we are using remote canvas we don't want to use acceleration in // non-remote layer managers, so we always use the fallback software one. - if (!gfxPlatform::UseRemoteCanvas() || - !gfxPlatform::IsBackendAccelerated( - gfxPlatform::GetPlatform()->GetPreferredCanvasBackend())) { + // If will-read-frequently is set, avoid using the preferred backend in + // favor of the fallback backend in case the preferred backend provides + // acceleration. + if (!aWillReadFrequently && + (!gfxPlatform::UseRemoteCanvas() || + !gfxPlatform::IsBackendAccelerated( + gfxPlatform::GetPlatform()->GetPreferredCanvasBackend()))) { bufferProvider = PersistentBufferProviderBasic::Create( aSize, aFormat, gfxPlatform::GetPlatform()->GetPreferredCanvasBackend()); diff --git a/layout/painting/WindowRenderer.h b/layout/painting/WindowRenderer.h index e018a4cf563c..660d2b42ddfc 100644 --- a/layout/painting/WindowRenderer.h +++ b/layout/painting/WindowRenderer.h @@ -200,7 +200,8 @@ class WindowRenderer : public FrameRecorder { */ virtual already_AddRefed CreatePersistentBufferProvider(const mozilla::gfx::IntSize& aSize, - mozilla::gfx::SurfaceFormat aFormat); + mozilla::gfx::SurfaceFormat aFormat, + bool aWillReadFrequently = false); // Helper wrappers around cast to impl and then cast again.