From 4cc0ee5f477b709592c400aefdb7eb3d195647fa Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 1 Jun 2026 10:40:42 +0200 Subject: [PATCH] UI/Qt: Keep macOS chrome out of RHI flushes Stop forcing RHI for every QWidget on macOS. The web content view is the only widget that needs Metal, and QRhiWidget already requests that. Make the web content view a native child before parenting it into the tab UI so Qt does not propagate its RHI config to the browser window backing store. This keeps chrome repaints on the normal Cocoa backing store path instead of copying the full window backing store into a texture. --- UI/Qt/WebContentView.cpp | 19 +++++++++++++++++-- UI/Qt/main.cpp | 8 ++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cpp index e00d46fb45..961103c7cd 100644 --- a/UI/Qt/WebContentView.cpp +++ b/UI/Qt/WebContentView.cpp @@ -53,10 +53,25 @@ namespace Ladybird { bool is_using_dark_system_theme(QWidget&); -WebContentView::WebContentView(QWidget* window, RefPtr parent_client, size_t page_index, WebContentViewInitialState initial_state) - : WebContentViewBase(window) +static QWidget* initial_web_content_view_parent([[maybe_unused]] QWidget* window) { #ifdef AK_OS_MACOS + return nullptr; +#else + return window; +#endif +} + +WebContentView::WebContentView(QWidget* window, RefPtr parent_client, size_t page_index, WebContentViewInitialState initial_state) + : WebContentViewBase(initial_web_content_view_parent(window)) +{ +#ifdef AK_OS_MACOS + // Keep the QRhiWidget out of the top-level QWidget backing store. If it is + // parented before becoming native, Qt propagates its RHI config to the whole + // browser window and uploads the full backing store texture on chrome repaints. + setAttribute(Qt::WA_DontCreateNativeAncestors); + setAttribute(Qt::WA_NativeWindow); + setParent(window); setApi(QRhiWidget::Api::Metal); #endif diff --git a/UI/Qt/main.cpp b/UI/Qt/main.cpp index 9c3e01d0b4..316009ce9c 100644 --- a/UI/Qt/main.cpp +++ b/UI/Qt/main.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) @@ -46,10 +47,9 @@ ErrorOr ladybird_main(Main::Arguments arguments) AK::set_rich_debug_enabled(true); #ifdef AK_OS_MACOS - if (!qEnvironmentVariableIsSet("QT_WIDGETS_RHI")) - qputenv("QT_WIDGETS_RHI", "1"); - if (!qEnvironmentVariableIsSet("QT_WIDGETS_RHI_BACKEND")) - qputenv("QT_WIDGETS_RHI_BACKEND", "metal"); + // The web content view is a native QRhiWidget child. Keep it from forcing + // every sibling in the tab UI to become native as well. + QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); #endif auto app = TRY(Ladybird::Application::create(arguments));