Skip to content

Truly independent web browser

UI/Qt+LibWebView+Hub: Show a bar while pages are painted on the CPU

Luke Wilde53c26303efa6
diff --git a/Documentation/UI/QuietDesign.md b/Documentation/UI/QuietDesign.md
index 0483379366a..7c41d9d8c6f 100644
--- a/Documentation/UI/QuietDesign.md
+++ b/Documentation/UI/QuietDesign.md
@@ -543,7 +543,7 @@ settings.
1. Report a problem with this site (the site report flow, prefilled with the address):
only on a website
2. Report a bug: opens GitHub's new-issue page in a new tab, prefilled with version, OS
- and build where possible
+ and build where possible, and with whether the sandbox or GPU painting is off
3. Crash reports, "2 to review": only while reports are waiting; opens the review page.
The same amber dot as on the button sits just before "2 to review", so the label
stays aligned with the rows above it
@@ -613,6 +613,16 @@ sandbox is off. Websites are less isolated from your computer."
- Nothing else changes: no badge on the Ladybird button, no tint, nothing in the address
field (which describes the site, not the browser).
+### Painting on the CPU
+
+When GPU painting is off, whether because of `--force-cpu-painting`, because no GPU could be
+used or because painting on it failed, every window shows a notification bar, below the
+sandbox one when both show: "Pages are painted on the CPU, which can be slow."
+
+- A "Report a bug" text button, which opens a new bug report, and a close button.
+- Closing it in one window closes it in every window until the browser is started again.
+ Nothing remembers it, so a browser that keeps painting on the CPU keeps saying so.
+
### Ladybird menu
- 280 px wide, 6 px padding, 26 px rows. Groups, in order:
diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp
index dc04180ea1a..b1b1f1ef224 100644
--- a/Libraries/LibWebView/Application.cpp
+++ b/Libraries/LibWebView/Application.cpp
@@ -2216,7 +2216,11 @@ PlatformFeatures::ProcessFeatures Application::platform_features_for(FeatureProc
ErrorOr<void> Application::launch_compositor_process()
{
VERIFY(!m_compositor_client);
- m_compositor_launched_features = m_platform_feature_decisions->features_for(FeatureProcess::Compositor).to_byte_string();
+ auto features = m_platform_feature_decisions->features_for(FeatureProcess::Compositor);
+ m_compositor_launched_features = features.to_byte_string();
+ auto gpu_painting_enabled = features.is_enabled(PlatformFeatures::Feature::GpuPainting);
+ if (exchange(m_compositor_gpu_painting_enabled, gpu_painting_enabled) != gpu_painting_enabled)
+ on_compositor_gpu_painting_changed();
m_compositor_client = TRY(WebView::launch_compositor_process(m_compositor_launched_features));
m_compositor_client->on_death = [this]() {
handle_compositor_process_death();
diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.h
index c9da6f0c809..605a6ca0377 100644
--- a/Libraries/LibWebView/Application.h
+++ b/Libraries/LibWebView/Application.h
@@ -418,6 +418,9 @@ public:
// Calls back once the features are decided from this launch's probe rather than from cached facts.
void when_platform_features_are_current(Function<void()>);
PlatformFeatures::ProcessFeatures platform_features_for(FeatureProcess) const;
+ // Whether GPU painting is in the features the Compositor was last launched with. Until the Compositor first launches,
+ // it counts as enabled.
+ bool compositor_gpu_painting_enabled() const { return m_compositor_gpu_painting_enabled; }
// Every feature's decision and the facts they were made from, for people to read.
JsonObject platform_features_report() const;
// The same as header lines of a report that leaves the machine: the features of one process or of all of them, the
@@ -457,6 +460,7 @@ protected:
virtual void on_devtools_enabled() const { }
virtual void on_devtools_disabled() const { }
+ virtual void on_compositor_gpu_painting_changed() const { }
Main::Arguments& arguments() { return m_arguments; }
@@ -671,6 +675,7 @@ private:
// Set when the Browser ends a Compositor to relaunch it with other features, which does not count as a crash.
bool m_compositor_relaunch_is_planned { false };
ByteString m_compositor_launched_features;
+ bool m_compositor_gpu_painting_enabled { true };
FeatureOverrides m_feature_overrides;
HashMap<PlatformFeatures::Feature, String> m_feature_runtime_failures;
diff --git a/Libraries/LibWebView/WebCompatReport.cpp b/Libraries/LibWebView/WebCompatReport.cpp
index 4dac7d4ef71..421ae386d8f 100644
--- a/Libraries/LibWebView/WebCompatReport.cpp
+++ b/Libraries/LibWebView/WebCompatReport.cpp
@@ -234,7 +234,7 @@ void WebCompatReport::start_submission()
submission->start();
}
-URL::URL new_bug_report_url(DisableSandbox disable_sandbox)
+URL::URL new_bug_report_url(BugReportDetails const& details)
{
StringBuilder url;
url.append("https://github.com/LadybirdBrowser/ladybird/issues/new?template=bug_report.yml"sv);
@@ -247,10 +247,14 @@ URL::URL new_bug_report_url(DisableSandbox disable_sandbox)
append_field("os"sv, platform);
append_field("architecture"sv, architecture == "x86_64"sv || architecture == "AArch64"sv ? architecture : "Other"sv);
append_field("commit"sv, LADYBIRD_COMMIT);
- auto build_flags = ByteString::formatted("Ladybird {}, {}", browser_version, build_configuration);
- if (disable_sandbox == DisableSandbox::Yes)
- build_flags = ByteString::formatted("{}, sandbox: off", build_flags);
- append_field("build-flags"sv, build_flags);
+
+ StringBuilder build_flags;
+ build_flags.appendff("Ladybird {}, {}", browser_version, build_configuration);
+ if (details.disable_sandbox == DisableSandbox::Yes)
+ build_flags.append(", sandbox: off"sv);
+ if (!details.gpu_painting_enabled)
+ build_flags.append(", GPU painting: off"sv);
+ append_field("build-flags"sv, build_flags.string_view());
return URL::Parser::basic_parse(url.string_view()).release_value();
}
diff --git a/Libraries/LibWebView/WebCompatReport.h b/Libraries/LibWebView/WebCompatReport.h
index cd6ab600382..c8c8f47eab2 100644
--- a/Libraries/LibWebView/WebCompatReport.h
+++ b/Libraries/LibWebView/WebCompatReport.h
@@ -90,7 +90,13 @@ private:
RefPtr<ReportSubmission> m_submission;
};
-// A new issue on GitHub, with what we know of this build already filled in.
-WEBVIEW_API URL::URL new_bug_report_url(DisableSandbox);
+// What a new bug report says about how this browser runs, beyond the details of its build.
+struct BugReportDetails {
+ DisableSandbox disable_sandbox { DisableSandbox::No };
+ bool gpu_painting_enabled { true };
+};
+
+// A new issue on GitHub, with the given details and what we know of this build already filled in.
+WEBVIEW_API URL::URL new_bug_report_url(BugReportDetails const&);
}
diff --git a/Services/Hub/Application.cpp b/Services/Hub/Application.cpp
index 672e10651ae..7070c7e5767 100644
--- a/Services/Hub/Application.cpp
+++ b/Services/Hub/Application.cpp
@@ -398,6 +398,12 @@ void Application::on_devtools_disabled() const
ui->async_app_did_disable_devtools();
}
+void Application::on_compositor_gpu_painting_changed() const
+{
+ if (auto* ui = ConnectionFromUI::the())
+ ui->async_app_gpu_painting_changed(compositor_gpu_painting_enabled());
+}
+
void Application::create_platform_actions()
{
if (m_host)
diff --git a/Services/Hub/Application.h b/Services/Hub/Application.h
index 2f753baef28..94ea5caa379 100644
--- a/Services/Hub/Application.h
+++ b/Services/Hub/Application.h
@@ -107,6 +107,7 @@ private:
virtual bool captures_browser_crashes() const override { return true; }
virtual void on_devtools_enabled() const override;
virtual void on_devtools_disabled() const override;
+ virtual void on_compositor_gpu_painting_changed() const override;
virtual void create_platform_actions() override;
virtual Optional<String> ui_font_family() const override;
virtual Web::CSS::PreferredColorScheme interface_color_scheme() const override;
diff --git a/Services/Hub/ConnectionFromUI.cpp b/Services/Hub/ConnectionFromUI.cpp
index 51cf8cbbd95..65df9bb4d78 100644
--- a/Services/Hub/ConnectionFromUI.cpp
+++ b/Services/Hub/ConnectionFromUI.cpp
@@ -568,6 +568,7 @@ Messages::HubServer::InitializeResponse ConnectionFromUI::initialize()
state.blocks_pop_ups = Application::the().blocks_pop_ups();
state.devtools_enabled = Application::the().devtools_enabled();
state.sandbox_is_disabled = options.disable_sandbox == WebView::DisableSandbox::Yes;
+ state.gpu_painting_enabled = Application::the().compositor_gpu_painting_enabled();
state.downloads = downloads();
state.urls = options.urls;
state.raw_urls = options.raw_urls;
diff --git a/Services/Hub/HubClient.ipc b/Services/Hub/HubClient.ipc
index 8eb17af6ba6..cbac8eef77a 100644
--- a/Services/Hub/HubClient.ipc
+++ b/Services/Hub/HubClient.ipc
@@ -154,6 +154,7 @@ struct Hub::InitialState {
bool blocks_pop_ups;
bool devtools_enabled;
bool sandbox_is_disabled;
+ bool gpu_painting_enabled;
Vector<Hub::DownloadState> downloads;
Vector<URL::URL> urls;
Vector<ByteString> raw_urls;
@@ -300,6 +301,7 @@ endpoint HubClient
app_quit_for_signal() =|
app_did_enable_devtools(u16 port) =|
app_did_disable_devtools() =|
+ app_gpu_painting_changed(bool gpu_painting_enabled) =|
app_open_urls_in_new_tabs(Vector<URL::URL> urls) =|
app_activate_or_open_tab_with_url(URL::URL url) =|
app_open_view_in_new_tab(u64 view_id, Optional<u64> source_view_id, WebView::IsPrivate is_private, Web::HTML::ActivateTab activate_tab) =|
diff --git a/Tests/LibWebView/TestWebCompatReport.cpp b/Tests/LibWebView/TestWebCompatReport.cpp
index d06050828f6..edb4a724e46 100644
--- a/Tests/LibWebView/TestWebCompatReport.cpp
+++ b/Tests/LibWebView/TestWebCompatReport.cpp
@@ -227,3 +227,21 @@ TEST_CASE(web_compat_report)
outln("PASS: Web compatibility reports reach the report server in the format it expects");
}
+
+TEST_CASE(new_bug_report_url)
+{
+ auto plain_url = WebView::new_bug_report_url({}).serialize();
+ auto plain = plain_url.bytes_as_string_view();
+ EXPECT(plain.starts_with("https://github.com/LadybirdBrowser/ladybird/issues/new?template=bug_report.yml&"sv));
+ EXPECT(plain.contains("&build-flags=Ladybird%20"sv));
+ EXPECT(!plain.contains("sandbox"sv));
+ EXPECT(!plain.contains("painting"sv));
+
+ WebView::BugReportDetails details {
+ .disable_sandbox = WebView::DisableSandbox::Yes,
+ .gpu_painting_enabled = false,
+ };
+ auto detailed_url = WebView::new_bug_report_url(details).serialize();
+ auto detailed = detailed_url.bytes_as_string_view();
+ EXPECT(detailed.ends_with("%2C%20sandbox%3A%20off%2C%20GPU%20painting%3A%20off"sv));
+}
diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp
index 65362e83635..4cad914afe2 100644
--- a/UI/Qt/Application.cpp
+++ b/UI/Qt/Application.cpp
@@ -52,6 +52,7 @@
#include <LibWebView/Translator.h>
#include <LibWebView/URL.h>
#include <LibWebView/Utilities.h>
+#include <LibWebView/WebCompatReport.h>
#include <LibWebView/WebContentPage.h>
#include <UI/Qt/Application.h>
#include <UI/Qt/BookmarkDialog.h>
@@ -960,6 +961,7 @@ ErrorOr<void> Application::connect_to_hub(Main::Arguments const& arguments)
m_browser_options.devtools_port = state.devtools_port;
if (state.devtools_enabled)
m_devtools_port = state.devtools_port;
+ m_gpu_painting_enabled = state.gpu_painting_enabled;
m_profile_is_temporary = state.profile_is_temporary;
# if defined(AK_OS_MACOS)
set_profile_application_icon(state.profile_identifier, state.profile_identity, state.profile_is_temporary);
@@ -1214,6 +1216,7 @@ void Application::create_platform_actions()
});
if (hub.devtools_enabled())
m_devtools_port = WebView::Application::browser_options().devtools_port;
+ m_gpu_painting_enabled = hub.compositor_gpu_painting_enabled();
RemoteDownloads::the().set_downloads(Hub::ConnectionFromUI::downloads());
#endif
@@ -2970,6 +2973,34 @@ void Application::did_disable_devtools()
}
}
+URL::URL Application::new_bug_report_url() const
+{
+ return WebView::new_bug_report_url({
+ .disable_sandbox = browser_options().disable_sandbox,
+ .gpu_painting_enabled = m_gpu_painting_enabled,
+ });
+}
+
+void Application::did_change_gpu_painting(bool enabled)
+{
+ m_gpu_painting_enabled = enabled;
+ update_cpu_painting_bars();
+}
+
+void Application::dismiss_cpu_painting_bar()
+{
+ m_cpu_painting_bar_dismissed = true;
+ update_cpu_painting_bars();
+}
+
+void Application::update_cpu_painting_bars() const
+{
+ for (auto* widget : QApplication::topLevelWidgets()) {
+ if (auto* window = as_if<BrowserWindow>(widget))
+ window->tab_widget().update_cpu_painting_bar();
+ }
+}
+
void Application::on_recently_closed_entries_changed() const
{
update_reopen_recently_closed_actions();
diff --git a/UI/Qt/Application.h b/UI/Qt/Application.h
index 3e4e5ddd2cd..f3e3e47a61c 100644
--- a/UI/Qt/Application.h
+++ b/UI/Qt/Application.h
@@ -87,6 +87,9 @@ public:
#endif
Optional<u16> devtools_port() const { return m_devtools_port; }
+ URL::URL new_bug_report_url() const;
+ bool shows_cpu_painting_bar() const { return !m_gpu_painting_enabled && !m_cpu_painting_bar_dismissed; }
+ void dismiss_cpu_painting_bar();
bool has_translator() const;
WebView::MicrophoneAuthorizer* microphone_authorizer() { return m_microphone_authorizer.ptr(); }
WebView::DefaultBrowser* default_browser() { return m_default_browser.ptr(); }
@@ -316,6 +319,8 @@ private:
void did_enable_devtools(u16 port);
void did_disable_devtools();
+ void did_change_gpu_painting(bool enabled);
+ void update_cpu_painting_bars() const;
void on_recently_closed_entries_changed() const;
void did_clear_history_since(UnixDateTime);
void create_session_store(ByteString const& data_directory, bool persists_sessions);
@@ -326,6 +331,8 @@ private:
String m_command_line;
Optional<u16> m_devtools_port;
+ bool m_gpu_painting_enabled { true };
+ bool m_cpu_painting_bar_dismissed { false };
#ifdef LADYBIRD_HUB_IN_OWN_PROCESS
ErrorOr<void> connect_to_hub(Main::Arguments const&);
diff --git a/UI/Qt/HubConnection.cpp b/UI/Qt/HubConnection.cpp
index f5ce0b735fa..d33933d6f87 100644
--- a/UI/Qt/HubConnection.cpp
+++ b/UI/Qt/HubConnection.cpp
@@ -323,6 +323,11 @@ void HubConnection::app_did_disable_devtools()
Application::the().did_disable_devtools();
}
+void HubConnection::app_gpu_painting_changed(bool gpu_painting_enabled)
+{
+ Application::the().did_change_gpu_painting(gpu_painting_enabled);
+}
+
void HubConnection::app_open_urls_in_new_tabs(Vector<URL::URL> urls)
{
Application::the().open_urls_in_new_tabs(urls);
diff --git a/UI/Qt/HubConnection.h b/UI/Qt/HubConnection.h
index ec91c4845f5..a3442356721 100644
--- a/UI/Qt/HubConnection.h
+++ b/UI/Qt/HubConnection.h
@@ -137,6 +137,7 @@ private:
virtual void app_quit_for_signal() override;
virtual void app_did_enable_devtools(u16 port) override;
virtual void app_did_disable_devtools() override;
+ virtual void app_gpu_painting_changed(bool gpu_painting_enabled) override;
virtual void app_open_urls_in_new_tabs(Vector<URL::URL> urls) override;
virtual void app_activate_or_open_tab_with_url(URL::URL url) override;
virtual void app_open_view_in_new_tab(u64 view_id, Optional<u64> source_view_id, WebView::IsPrivate is_private, Web::HTML::ActivateTab activate_tab) override;
diff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cpp
index 3e3fd31b491..344a8f12f18 100644
--- a/UI/Qt/TabBar.cpp
+++ b/UI/Qt/TabBar.cpp
@@ -3110,6 +3110,7 @@ TabWidget::TabWidget(WebView::IsPrivate is_private, QWidget* parent)
m_notification_bar_column_layout->setContentsMargins(0, 0, 0, 0);
if (Application::browser_options().disable_sandbox == WebView::DisableSandbox::Yes)
show_notification_bar(NotificationBarSlot::SandboxOff, "The sandbox is off. Websites are less isolated from your computer.");
+ update_cpu_painting_bar();
m_ladybird_button = new LadybirdButton(is_private, this);
@@ -3529,6 +3530,27 @@ void TabWidget::hide_notification_bar(NotificationBarSlot slot)
bar = nullptr;
}
+void TabWidget::update_cpu_painting_bar()
+{
+ if (!Application::the().shows_cpu_painting_bar()) {
+ hide_notification_bar(NotificationBarSlot::CpuPainting);
+ return;
+ }
+ if (m_notification_bars[to_underlying(NotificationBarSlot::CpuPainting)])
+ return;
+
+ Vector<NotificationBar::Button> buttons;
+ buttons.append({ "Report a bug", [this] {
+ auto* browser_window = qobject_cast<BrowserWindow*>(window());
+ if (!browser_window)
+ return;
+ browser_window->new_tab_from_url(Application::the().new_bug_report_url(), Web::HTML::ActivateTab::Yes, BrowserWindow::TabLocation::after_current_tab());
+ } });
+ show_notification_bar(NotificationBarSlot::CpuPainting, "Pages are painted on the CPU, which can be slow.", AK::move(buttons), [] {
+ Application::the().dismiss_cpu_painting_bar();
+ });
+}
+
void TabWidget::set_window_controls_visible(bool visible)
{
auto changed = m_window_controls_visible != visible;
diff --git a/UI/Qt/TabBar.h b/UI/Qt/TabBar.h
index efd58a407b8..d45ea291805 100644
--- a/UI/Qt/TabBar.h
+++ b/UI/Qt/TabBar.h
@@ -336,9 +336,11 @@ public:
enum class NotificationBarSlot : u8 {
SandboxOff,
+ CpuPainting,
};
void show_notification_bar(NotificationBarSlot, QString const& message, Vector<NotificationBar::Button> = {}, Function<void()> on_close = {});
void hide_notification_bar(NotificationBarSlot);
+ void update_cpu_painting_bar();
void set_new_tab_action(QAction* action);
void set_window_controls_visible(bool);
@@ -468,7 +470,7 @@ private:
BookmarksBarContainer* m_bookmarks_bar { nullptr };
QWidget* m_notification_bar_column { nullptr };
QBoxLayout* m_notification_bar_column_layout { nullptr };
- Array<NotificationBar*, 1> m_notification_bars {};
+ Array<NotificationBar*, 2> m_notification_bars {};
QWidget* m_page_column { nullptr };
QWidget* m_toolbar_placeholder { nullptr };
bool m_toolbar_follows_page_column { false };
diff --git a/UI/Qt/WindowToolbar.cpp b/UI/Qt/WindowToolbar.cpp
index 907522e5f55..aa56a2481db 100644
--- a/UI/Qt/WindowToolbar.cpp
+++ b/UI/Qt/WindowToolbar.cpp
@@ -2109,7 +2109,7 @@ void WindowToolbar::show_feedback_popover()
m_tab->view().report_website_issue();
};
m_feedback_popover->on_report_bug = [this] {
- browser_window().new_tab_from_url(WebView::new_bug_report_url(Application::browser_options().disable_sandbox), Web::HTML::ActivateTab::Yes, BrowserWindow::TabLocation::after_current_tab());
+ browser_window().new_tab_from_url(Application::the().new_bug_report_url(), Web::HTML::ActivateTab::Yes, BrowserWindow::TabLocation::after_current_tab());
};
m_feedback_popover->on_review_crash_reports = [this] {
browser_window().new_tab_from_url(URL::URL::about("crashes"sv), Web::HTML::ActivateTab::Yes, BrowserWindow::TabLocation::after_current_tab());