Jelajahi Sumber

LibWebView+WebContent: Add a `--force-cpu-painting` option

This option forces Skia to use the CPU backend rather than using the
GPU.
Tim Ledbetter 1 tahun lalu
induk
melakukan
2854113ee6

+ 2 - 0
Ladybird/HelperProcess.cpp

@@ -102,6 +102,8 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(
         arguments.append("--enable-http-cache"sv);
     if (web_content_options.expose_internals_object == WebView::ExposeInternalsObject::Yes)
         arguments.append("--expose-internals-object"sv);
+    if (web_content_options.force_cpu_painting == WebView::ForceCPUPainting::Yes)
+        arguments.append("--force-cpu-painting"sv);
     if (auto server = mach_server_name(); server.has_value()) {
         arguments.append("--mach-server-name"sv);
         arguments.append(server.value());

+ 7 - 3
Ladybird/WebContent/main.cpp

@@ -104,6 +104,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     bool log_all_js_exceptions = false;
     bool enable_idl_tracing = false;
     bool enable_http_cache = false;
+    bool force_cpu_painting = false;
 
     Core::ArgsParser args_parser;
     args_parser.add_option(command_line, "Chrome process command line", "command-line", 0, "command_line");
@@ -120,6 +121,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     args_parser.add_option(log_all_js_exceptions, "Log all JavaScript exceptions", "log-all-js-exceptions");
     args_parser.add_option(enable_idl_tracing, "Enable IDL tracing", "enable-idl-tracing");
     args_parser.add_option(enable_http_cache, "Enable HTTP cache", "enable-http-cache");
+    args_parser.add_option(force_cpu_painting, "Force CPU painting", "force-cpu-painting");
 
     args_parser.parse(arguments);
 
@@ -127,15 +129,17 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
         Core::Process::wait_for_debugger_and_break();
     }
 
-    // Layout test mode implies internals object is exposed
-    if (is_layout_test_mode)
+    // Layout test mode implies internals object is exposed and the Skia CPU backend is used
+    if (is_layout_test_mode) {
         expose_internals_object = true;
+        force_cpu_painting = true;
+    }
 
     Web::set_chrome_process_command_line(command_line);
     Web::set_chrome_process_executable_path(executable_path);
 
     // Always use the CPU backend for layout tests, as the GPU backend is not deterministic
-    WebContent::PageClient::set_use_skia_painter(is_layout_test_mode ? WebContent::PageClient::UseSkiaPainter::CPUBackend : WebContent::PageClient::UseSkiaPainter::GPUBackendIfAvailable);
+    WebContent::PageClient::set_use_skia_painter(force_cpu_painting ? WebContent::PageClient::UseSkiaPainter::CPUBackend : WebContent::PageClient::UseSkiaPainter::GPUBackendIfAvailable);
 
     if (enable_http_cache) {
         Web::Fetch::Fetching::g_http_cache_enabled = true;

+ 3 - 0
Userland/Libraries/LibWebView/Application.cpp

@@ -45,6 +45,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
     bool enable_idl_tracing = false;
     bool enable_http_cache = false;
     bool expose_internals_object = false;
+    bool force_cpu_painting = false;
 
     Core::ArgsParser args_parser;
     args_parser.set_general_help("The Ladybird web browser :^)");
@@ -61,6 +62,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
     args_parser.add_option(enable_idl_tracing, "Enable IDL tracing", "enable-idl-tracing");
     args_parser.add_option(enable_http_cache, "Enable HTTP cache", "enable-http-cache");
     args_parser.add_option(expose_internals_object, "Expose internals object", "expose-internals-object");
+    args_parser.add_option(force_cpu_painting, "Force CPU painting", "force-cpu-painting");
 
     create_platform_arguments(args_parser);
     args_parser.parse(arguments);
@@ -96,6 +98,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
         .enable_idl_tracing = enable_idl_tracing ? EnableIDLTracing::Yes : EnableIDLTracing::No,
         .enable_http_cache = enable_http_cache ? EnableHTTPCache::Yes : EnableHTTPCache::No,
         .expose_internals_object = expose_internals_object ? ExposeInternalsObject::Yes : ExposeInternalsObject::No,
+        .force_cpu_painting = force_cpu_painting ? ForceCPUPainting::Yes : ForceCPUPainting::No,
     };
 
     create_platform_options(m_chrome_options, m_web_content_options);

+ 6 - 0
Userland/Libraries/LibWebView/Options.h

@@ -79,6 +79,11 @@ enum class ExposeInternalsObject {
     Yes,
 };
 
+enum class ForceCPUPainting {
+    No,
+    Yes,
+};
+
 struct WebContentOptions {
     String command_line;
     String executable_path;
@@ -89,6 +94,7 @@ struct WebContentOptions {
     EnableIDLTracing enable_idl_tracing { EnableIDLTracing::No };
     EnableHTTPCache enable_http_cache { EnableHTTPCache::No };
     ExposeInternalsObject expose_internals_object { ExposeInternalsObject::No };
+    ForceCPUPainting force_cpu_painting { ForceCPUPainting::No };
 };
 
 }