Skip to content

Truly independent web browser

Everywhere: Decide the Compositor's GPU features from a system probe

Zaggy10247a57f19e7995
diff --git a/Libraries/CMakeLists.txt b/Libraries/CMakeLists.txt
index 99fc4a166ee..a5e92d70df3 100644
--- a/Libraries/CMakeLists.txt
+++ b/Libraries/CMakeLists.txt
@@ -41,6 +41,7 @@ if (ENABLE_GUI_TARGETS)
add_subdirectory(LibMediaCodecs)
add_subdirectory(LibMedia)
add_subdirectory(LibMediaClient)
+ add_subdirectory(LibPlatformFeatures)
add_subdirectory(LibWebCommon)
add_subdirectory(LibCompositing)
add_subdirectory(LibWeb)
diff --git a/Libraries/LibGfx/VulkanContext.cpp b/Libraries/LibGfx/VulkanContext.cpp
index 79c6594b5b5..6de6aa2e843 100644
--- a/Libraries/LibGfx/VulkanContext.cpp
+++ b/Libraries/LibGfx/VulkanContext.cpp
@@ -53,7 +53,7 @@ static ErrorOr<VkInstance> create_instance(uint32_t api_version)
return instance;
}
-static ErrorOr<VkPhysicalDevice> pick_physical_device(VkInstance instance, Optional<GpuDeviceIdentity> const& preferred_device)
+ErrorOr<VkPhysicalDevice> pick_physical_device(VkInstance instance, Optional<GpuDeviceIdentity> const& preferred_device)
{
uint32_t device_count = 0;
vkEnumeratePhysicalDevices(instance, &device_count, nullptr);
@@ -121,7 +121,7 @@ static ReadonlySpan<char const*> device_extensions_to_enable(VkPhysicalDevice)
}
#endif
-static bool device_can_sample_through_ycbcr_conversion(VkPhysicalDevice physical_device)
+bool device_can_sample_through_ycbcr_conversion(VkPhysicalDevice physical_device)
{
VkPhysicalDeviceSamplerYcbcrConversionFeatures ycbcr_conversion_features {};
ycbcr_conversion_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES;
diff --git a/Libraries/LibGfx/VulkanContext.h b/Libraries/LibGfx/VulkanContext.h
index 9ac2edf3129..39d5f31eebf 100644
--- a/Libraries/LibGfx/VulkanContext.h
+++ b/Libraries/LibGfx/VulkanContext.h
@@ -42,6 +42,9 @@ struct VulkanContext {
// The preferred device is picked when it is present, since memory the context shares can only be imported on the same one.
ErrorOr<VulkanContext> create_vulkan_context(Optional<GpuDeviceIdentity> const& preferred_device = {});
+// The device a context would be created on, which the system probe describes without creating one.
+ErrorOr<VkPhysicalDevice> pick_physical_device(VkInstance, Optional<GpuDeviceIdentity> const& preferred_device);
+bool device_can_sample_through_ycbcr_conversion(VkPhysicalDevice);
GpuDeviceIdentity gpu_device_identity_of(VkPhysicalDevice);
}
diff --git a/Libraries/LibPlatformFeatures/Build.h b/Libraries/LibPlatformFeatures/Build.h
new file mode 100644
index 00000000000..0c610fc10ec
--- /dev/null
+++ b/Libraries/LibPlatformFeatures/Build.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Assertions.h>
+#include <LibPlatformFeatures/Feature.h>
+
+namespace PlatformFeatures {
+
+// What a build of Ladybird can do, which decides the features that exist in it at all. CMake picks the code only some
+// builds can compile, and everything else asks this_build.
+struct Build {
+ // The Compositor paints through Vulkan, on the GPU the system probe describes.
+ bool paints_through_vulkan { false };
+ // Vulkan images are shared between processes as dma-bufs.
+ bool shares_vulkan_images { false };
+
+
+ constexpr bool includes(Feature feature) const
+ {
+ switch (feature) {
+ case Feature::GpuPainting:
+ return true;
+ case Feature::YCbCrImport:
+ return shares_vulkan_images;
+ }
+ VERIFY_NOT_REACHED();
+ }
+
+ // A build with every feature, so that tests can decide them all on any platform.
+ static constexpr Build with_every_feature()
+ {
+ return { .paints_through_vulkan = true, .shares_vulkan_images = true };
+ }
+};
+
+namespace Detail {
+
+#ifdef USE_VULKAN
+constexpr bool paints_through_vulkan = true;
+#else
+constexpr bool paints_through_vulkan = false;
+#endif
+
+#ifdef USE_VULKAN_DMABUF_IMAGES
+constexpr bool shares_vulkan_images = true;
+#else
+constexpr bool shares_vulkan_images = false;
+#endif
+
+}
+
+constexpr Build this_build {
+ .paints_through_vulkan = Detail::paints_through_vulkan,
+ .shares_vulkan_images = Detail::shares_vulkan_images,
+};
+
+}
diff --git a/Libraries/LibPlatformFeatures/CMakeLists.txt b/Libraries/LibPlatformFeatures/CMakeLists.txt
new file mode 100644
index 00000000000..e1a7f040a9c
--- /dev/null
+++ b/Libraries/LibPlatformFeatures/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(SOURCES
+ Feature.cpp
+ ProcessFeatures.cpp
+ SystemFacts.cpp
+)
+
+ladybird_lib(LibPlatformFeatures platformfeatures)
diff --git a/Libraries/LibPlatformFeatures/Feature.cpp b/Libraries/LibPlatformFeatures/Feature.cpp
new file mode 100644
index 00000000000..9b1c639f6f8
--- /dev/null
+++ b/Libraries/LibPlatformFeatures/Feature.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibPlatformFeatures/Feature.h>
+
+namespace PlatformFeatures {
+
+StringView feature_id(Feature feature)
+{
+ switch (feature) {
+ case Feature::GpuPainting:
+ return "gpu_painting"sv;
+ case Feature::YCbCrImport:
+ return "ycbcr_import"sv;
+ }
+ VERIFY_NOT_REACHED();
+}
+
+Optional<Feature> feature_from_id(StringView id)
+{
+ for (auto feature : all_features) {
+ if (feature_id(feature) == id)
+ return feature;
+ }
+ return {};
+}
+
+FeatureProcess process_of(Feature feature)
+{
+ switch (feature) {
+ case Feature::GpuPainting:
+ case Feature::YCbCrImport:
+ return FeatureProcess::Compositor;
+ }
+ VERIFY_NOT_REACHED();
+}
+
+Optional<Feature> dependency_of(Feature feature)
+{
+ switch (feature) {
+ case Feature::GpuPainting:
+ return {};
+ case Feature::YCbCrImport:
+ return Feature::GpuPainting;
+ }
+ VERIFY_NOT_REACHED();
+}
+
+StringView process_name(FeatureProcess process)
+{
+ switch (process) {
+ case FeatureProcess::Compositor:
+ return "Compositor"sv;
+ }
+ VERIFY_NOT_REACHED();
+}
+
+}
diff --git a/Libraries/LibPlatformFeatures/Feature.h b/Libraries/LibPlatformFeatures/Feature.h
new file mode 100644
index 00000000000..1702068aa1c
--- /dev/null
+++ b/Libraries/LibPlatformFeatures/Feature.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Array.h>
+#include <AK/Format.h>
+#include <AK/Optional.h>
+#include <AK/StringView.h>
+
+namespace PlatformFeatures {
+
+// The process that uses a feature, and the only one told whether it is enabled.
+enum class FeatureProcess : u8 {
+ Compositor,
+};
+
+// A feature is only enabled while the feature it depends on is, so each one is declared after its dependency.
+enum class Feature : u8 {
+ GpuPainting,
+ YCbCrImport,
+};
+
+constexpr Array all_features {
+ Feature::GpuPainting,
+ Feature::YCbCrImport,
+};
+
+StringView feature_id(Feature);
+Optional<Feature> feature_from_id(StringView);
+FeatureProcess process_of(Feature);
+Optional<Feature> dependency_of(Feature);
+
+StringView process_name(FeatureProcess);
+
+}
+
+template<>
+struct AK::Formatter<PlatformFeatures::Feature> : Formatter<StringView> {
+ ErrorOr<void> format(FormatBuilder& builder, PlatformFeatures::Feature feature)
+ {
+ return Formatter<StringView>::format(builder, PlatformFeatures::feature_id(feature));
+ }
+};
diff --git a/Libraries/LibPlatformFeatures/ProcessFeatures.cpp b/Libraries/LibPlatformFeatures/ProcessFeatures.cpp
new file mode 100644
index 00000000000..3a47e499d5b
--- /dev/null
+++ b/Libraries/LibPlatformFeatures/ProcessFeatures.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <AK/NeverDestroyed.h>
+#include <AK/StringBuilder.h>
+#include <AK/Vector.h>
+#include <LibPlatformFeatures/ProcessFeatures.h>
+
+namespace PlatformFeatures {
+
+static NeverDestroyed<Optional<ProcessFeatures>> s_current_process_features;
+
+ErrorOr<ProcessFeatures> ProcessFeatures::from_string(FeatureProcess process, StringView string)
+{
+ ProcessFeatures features { process };
+ for (auto id : string.split_view(',')) {
+ auto feature = feature_from_id(id);
+ if (!feature.has_value())
+ return Error::from_string_literal("Unknown platform feature");
+ if (process_of(*feature) != process)
+ return Error::from_string_literal("A platform feature was given to a process that does not use it");
+ features.set_enabled(*feature);
+ }
+ return features;
+}
+
+ByteString ProcessFeatures::to_byte_string() const
+{
+ StringBuilder builder;
+ for (auto feature : all_features) {
+ if (!m_enabled.contains(feature))
+ continue;
+ if (!builder.is_empty())
+ builder.append(',');
+ builder.append(feature_id(feature));
+ }
+ return builder.to_byte_string();
+}
+
+bool ProcessFeatures::is_enabled(Feature feature) const
+{
+ VERIFY(process_of(feature) == m_process);
+ return m_enabled.contains(feature);
+}
+
+void ProcessFeatures::set_enabled(Feature feature)
+{
+ VERIFY(process_of(feature) == m_process);
+ m_enabled.set(feature);
+}
+
+void ProcessFeatures::initialize_for_current_process(ProcessFeatures features)
+{
+ VERIFY(!s_current_process_features->has_value());
+ *s_current_process_features = move(features);
+}
+
+ProcessFeatures const& ProcessFeatures::the()
+{
+ return s_current_process_features->value();
+}
+
+}
diff --git a/Libraries/LibPlatformFeatures/ProcessFeatures.h b/Libraries/LibPlatformFeatures/ProcessFeatures.h
new file mode 100644
index 00000000000..eb2efc2e488
--- /dev/null
+++ b/Libraries/LibPlatformFeatures/ProcessFeatures.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/ByteString.h>
+#include <AK/Error.h>
+#include <AK/HashTable.h>
+#include <LibPlatformFeatures/Feature.h>
+
+namespace PlatformFeatures {
+
+// The features one process may use, decided by the Browser before launching it and fixed for the process's lifetime.
+class ProcessFeatures {
+public:
+ explicit ProcessFeatures(FeatureProcess process)
+ : m_process(process)
+ {
+ }
+
+ // The text form names the enabled features, comma-separated, so that it can be passed as an argument.
+ static ErrorOr<ProcessFeatures> from_string(FeatureProcess, StringView);
+ ByteString to_byte_string() const;
+
+ bool is_enabled(Feature) const;
+ void set_enabled(Feature);
+
+ static void initialize_for_current_process(ProcessFeatures);
+ static ProcessFeatures const& the();
+
+private:
+ FeatureProcess m_process;
+ HashTable<Feature> m_enabled;
+};
+
+}
diff --git a/Libraries/LibPlatformFeatures/SystemFacts.cpp b/Libraries/LibPlatformFeatures/SystemFacts.cpp
new file mode 100644
index 00000000000..97d63264288
--- /dev/null
+++ b/Libraries/LibPlatformFeatures/SystemFacts.cpp
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <AK/JsonValue.h>
+#include <LibPlatformFeatures/SystemFacts.h>
+
+namespace PlatformFeatures {
+
+// Drivers name themselves however they like, so their strings are bounded before they reach reports. Vulkan's are at
+// most 255 bytes, each of which may have become a three-byte replacement character.
+static constexpr size_t maximum_string_length = 1024;
+
+JsonObject SystemFacts::to_json() const
+{
+ JsonObject object;
+ if (gpu.has_value()) {
+ JsonObject gpu_object;
+ gpu_object.set("vendor_id"sv, gpu->vendor_id);
+ gpu_object.set("device_id"sv, gpu->device_id);
+ gpu_object.set("device_name"sv, gpu->device_name);
+ gpu_object.set("driver_id"sv, gpu->driver_id);
+ gpu_object.set("driver_name"sv, gpu->driver_name);
+ gpu_object.set("driver_info"sv, gpu->driver_info);
+ gpu_object.set("driver_version"sv, gpu->driver_version);
+ gpu_object.set("api_version"sv, gpu->api_version);
+ gpu_object.set("device_identity"sv, gpu->device_identity);
+ gpu_object.set("supports_ycbcr_sampling"sv, gpu->supports_ycbcr_sampling);
+ object.set("gpu"sv, move(gpu_object));
+ }
+ return object;
+}
+
+static ErrorOr<bool> read_bool(JsonObject const& object, StringView key)
+{
+ auto value = object.get_bool(key);
+ if (!value.has_value())
+ return Error::from_string_literal("System facts are missing a boolean");
+ return *value;
+}
+
+static ErrorOr<u32> read_u32(JsonObject const& object, StringView key)
+{
+ auto value = object.get_u32(key);
+ if (!value.has_value())
+ return Error::from_string_literal("System facts are missing a number");
+ return *value;
+}
+
+static ErrorOr<String> read_string(JsonObject const& object, StringView key)
+{
+ auto value = object.get_string(key);
+ if (!value.has_value())
+ return Error::from_string_literal("System facts are missing a string");
+ if (value->bytes().size() > maximum_string_length)
+ return Error::from_string_literal("A string in the system facts is too long");
+ return *value;
+}
+
+ErrorOr<SystemFacts> SystemFacts::from_json(StringView json)
+{
+ auto value = TRY(JsonValue::from_string(json));
+ if (!value.is_object())
+ return Error::from_string_literal("System facts are not an object");
+ return from_json(value.as_object());
+}
+
+ErrorOr<SystemFacts> SystemFacts::from_json(JsonObject const& object)
+{
+ SystemFacts facts;
+ if (object.has("gpu"sv)) {
+ auto gpu_object = object.get_object("gpu"sv);
+ if (!gpu_object.has_value())
+ return Error::from_string_literal("The GPU's system facts are not an object");
+ GpuFacts gpu;
+ gpu.vendor_id = TRY(read_u32(*gpu_object, "vendor_id"sv));
+ gpu.device_id = TRY(read_u32(*gpu_object, "device_id"sv));
+ gpu.device_name = TRY(read_string(*gpu_object, "device_name"sv));
+ gpu.driver_id = TRY(read_u32(*gpu_object, "driver_id"sv));
+ gpu.driver_name = TRY(read_string(*gpu_object, "driver_name"sv));
+ gpu.driver_info = TRY(read_string(*gpu_object, "driver_info"sv));
+ gpu.driver_version = TRY(read_u32(*gpu_object, "driver_version"sv));
+ gpu.api_version = TRY(read_u32(*gpu_object, "api_version"sv));
+ gpu.device_identity = TRY(read_string(*gpu_object, "device_identity"sv));
+ gpu.supports_ycbcr_sampling = TRY(read_bool(*gpu_object, "supports_ycbcr_sampling"sv));
+ facts.gpu = move(gpu);
+ }
+ return facts;
+}
+
+}
diff --git a/Libraries/LibPlatformFeatures/SystemFacts.h b/Libraries/LibPlatformFeatures/SystemFacts.h
new file mode 100644
index 00000000000..ea476692737
--- /dev/null
+++ b/Libraries/LibPlatformFeatures/SystemFacts.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Error.h>
+#include <AK/JsonObject.h>
+#include <AK/Optional.h>
+#include <AK/String.h>
+
+namespace PlatformFeatures {
+
+// The GPU that presents, as Vulkan describes it.
+struct GpuFacts {
+ u32 vendor_id { 0 };
+ u32 device_id { 0 };
+ String device_name;
+ // VkDriverId, which tells apart drivers for the same vendor's hardware.
+ u32 driver_id { 0 };
+ String driver_name;
+ String driver_info;
+ // Encoded by each driver in its own way, so it is only compared alongside the driver ID.
+ u32 driver_version { 0 };
+ u32 api_version { 0 };
+ String device_identity;
+
+ bool supports_ycbcr_sampling { false };
+
+ bool operator==(GpuFacts const&) const = default;
+};
+
+// Everything the blocklist decides from, collected by the system probe.
+struct SystemFacts {
+ Optional<GpuFacts> gpu;
+ // Set instead of the facts when the probe crashed, hung or reported something unreadable. Never serialized.
+ Optional<String> probe_failure;
+
+ bool operator==(SystemFacts const&) const = default;
+
+ JsonObject to_json() const;
+ static ErrorOr<SystemFacts> from_json(StringView);
+ static ErrorOr<SystemFacts> from_json(JsonObject const&);
+};
+
+}
diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp
index 5f8ffc690d7..90546d9dc7f 100644
--- a/Libraries/LibWebView/Application.cpp
+++ b/Libraries/LibWebView/Application.cpp
@@ -71,6 +71,7 @@
#include <LibWebView/SiteCompatibility.h>
#include <LibWebView/SpellChecker.h>
#include <LibWebView/StorageAreaRegistry.h>
+#include <LibWebView/SystemProbeClient.h>
#include <LibWebView/TabPerformanceMonitor.h>
#include <LibWebView/Translator.h>
#include <LibWebView/URL.h>
@@ -331,6 +332,19 @@ ErrorOr<void> Application::initialize(Main::Arguments const& arguments)
bool expose_experimental_interfaces = false;
bool expose_internals_object = false;
bool force_cpu_painting = false;
+ HashTable<PlatformFeatures::Feature> disabled_features;
+ HashTable<PlatformFeatures::Feature> force_enabled_features;
+ auto parse_feature_list = [](StringView list, HashTable<PlatformFeatures::Feature>& features) {
+ for (auto id : list.split_view(',')) {
+ auto feature = PlatformFeatures::feature_from_id(id);
+ if (!feature.has_value()) {
+ warnln("Unknown platform feature: {}", id);
+ return false;
+ }
+ features.set(*feature);
+ }
+ return true;
+ };
bool force_fontconfig = false;
bool collect_garbage_on_every_allocation = false;
bool disable_scrollbar_painting = false;
@@ -456,7 +470,25 @@ ErrorOr<void> Application::initialize(Main::Arguments const& arguments)
args_parser.add_option(enable_autoplay, "Enable multimedia autoplay", "enable-autoplay");
args_parser.add_option(expose_experimental_interfaces, "Expose experimental IDL interfaces", "expose-experimental-interfaces");
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");
+ args_parser.add_option(force_cpu_painting, "Force CPU painting, the same as --disable-features=gpu_painting", "force-cpu-painting");
+ args_parser.add_option(Core::ArgsParser::Option {
+ .argument_mode = Core::ArgsParser::OptionArgumentMode::Required,
+ .help_string = "Turn off platform features, and the features that depend on them",
+ .long_name = "disable-features",
+ .value_name = "feature,...",
+ .accept_value = [&](StringView value) -> ErrorOr<bool> {
+ return parse_feature_list(value, disabled_features);
+ },
+ });
+ args_parser.add_option(Core::ArgsParser::Option {
+ .argument_mode = Core::ArgsParser::OptionArgumentMode::Required,
+ .help_string = "Turn on platform features despite the blocklist, where the system supports them",
+ .long_name = "force-enable-features",
+ .value_name = "feature,...",
+ .accept_value = [&](StringView value) -> ErrorOr<bool> {
+ return parse_feature_list(value, force_enabled_features);
+ },
+ });
args_parser.add_option(force_fontconfig, "Force using fontconfig for font loading", "force-fontconfig");
args_parser.add_option(collect_garbage_on_every_allocation, "Collect garbage after every JS heap allocation", "collect-garbage-on-every-allocation", 'g');
args_parser.add_option(disable_scrollbar_painting, "Don't paint horizontal or vertical scrollbars on the main viewport", "disable-scrollbar-painting");
@@ -678,6 +710,14 @@ ErrorOr<void> Application::initialize(Main::Arguments const& arguments)
m_web_content_options.force_cpu_painting = ForceCPUPainting::Yes;
}
+ m_feature_overrides.disabled = move(disabled_features);
+ m_feature_overrides.force_enabled = move(force_enabled_features);
+ if (m_web_content_options.force_cpu_painting == ForceCPUPainting::Yes)
+ m_feature_overrides.disabled.set(PlatformFeatures::Feature::GpuPainting);
+ // Test results must not depend on the machine's GPU.
+ if (m_web_content_options.is_test_mode == IsTestMode::Yes)
+ m_feature_overrides.force_enabled.clear();
+
if (m_web_content_options.file_scheme_urls_have_tuple_origins == FileSchemeUrlsHaveTupleOrigins::Yes)
URL::set_file_scheme_urls_have_tuple_origins();
@@ -1104,7 +1144,9 @@ ErrorOr<NonnullRefPtr<WebContentClient>> Application::create_web_content_client(
auto initial_document_id = cross_process_id_allocator.allocate();
auto client = TRY(WebView::launch_web_content_process(session, initial_page_id, root_navigable_id));
- TRY(Application::the().connect_web_content_to_compositor(*client));
+ // A process launched while there is no Compositor is connected to it along with every other process once it is up.
+ if (m_compositor_client)
+ TRY(connect_web_content_to_compositor(*client));
// A tab's first process creates its traversable from this entry. A process hosting a navigable of an existing tab
// stands in for the canonical current entry.
@@ -1874,7 +1916,14 @@ ErrorOr<void> Application::launch_services()
m_image_decoder_manager = make<ImageDecoderManager>();
TRY(launch_request_server());
- TRY(launch_compositor_process());
+ if (prepare_platform_features() == CompositorLaunch::Now) {
+ TRY(launch_compositor_process());
+ } else {
+ // Pages opened in the meantime are attached to the Compositor once it is up, as after a crash.
+ when_platform_features_are_current([this] {
+ bring_up_compositor_process();
+ });
+ }
if (m_browser_options.devtools_port.has_value()) {
// Defer launching devtools until the entire application is initialized.
@@ -1887,10 +1936,125 @@ ErrorOr<void> Application::launch_services()
return {};
}
+static constexpr u32 system_facts_cache_format = 1;
+
+static ByteString platform_features_cache_path()
+{
+ auto const& profile = Application::profile();
+ return LexicalPath::join(profile.paths().cache, "SystemFacts.json"sv).string();
+}
+
+static Optional<SystemFacts> read_cached_system_facts(ByteString const& path)
+{
+ auto file = Core::File::open(path, Core::File::OpenMode::Read);
+ if (file.is_error())
+ return {};
+ auto contents = file.value()->read_until_eof();
+ if (contents.is_error())
+ return {};
+ auto json = JsonValue::from_string(contents.value());
+ if (json.is_error() || !json.value().is_object())
+ return {};
+ auto const& object = json.value().as_object();
+ if (object.get_u32("format"sv) != system_facts_cache_format)
+ return {};
+ auto facts_object = object.get_object("facts"sv);
+ if (!facts_object.has_value())
+ return {};
+ auto facts = SystemFacts::from_json(*facts_object);
+ if (facts.is_error())
+ return {};
+ return facts.release_value();
+}
+
+static ErrorOr<void> write_cached_system_facts(ByteString const& path, SystemFacts const& facts)
+{
+ JsonObject object;
+ object.set("format"sv, system_facts_cache_format);
+ object.set("facts"sv, facts.to_json());
+
+ // The file is replaced whole, so that a crash while writing it cannot leave half a cache behind.
+ auto temporary_path = ByteString::formatted("{}.new", path);
+ auto file = TRY(Core::File::open(temporary_path, Core::File::OpenMode::Write | Core::File::OpenMode::Truncate));
+ auto serialized = object.serialized();
+ TRY(file->write_until_depleted(serialized.bytes()));
+ file->close();
+ TRY(FileSystem::move_file(path, temporary_path));
+ return {};
+}
+
+Application::CompositorLaunch Application::prepare_platform_features()
+{
+ // Test results must not depend on the machine's GPU, and test mode paints on the CPU regardless of what it has.
+ if (m_web_content_options.is_test_mode == IsTestMode::Yes) {
+ reevaluate_platform_features();
+ return CompositorLaunch::Now;
+ }
+
+ auto cached_facts = read_cached_system_facts(platform_features_cache_path());
+ m_system_probe = SystemProbeClient::launch(platform_presentation_gpu_device(), [this](SystemFacts const& facts) {
+ system_facts_arrived(facts);
+ });
+ // A probe that could not be launched has already reported so.
+ if (m_system_probe->has_finished())
+ return CompositorLaunch::Now;
+
+ // The Compositor starts from the facts the last probe reported, unless it would not use them. Without them, it
+ // waits for this probe, which reports soon enough not to be worth starting the Compositor twice.
+ auto launch = CompositorLaunch::Now;
+ if (cached_facts.has_value())
+ m_system_facts = cached_facts.release_value();
+ else if (!PlatformFeatureDecisions::decides_without_facts(FeatureProcess::Compositor, m_feature_overrides))
+ launch = CompositorLaunch::WhenPlatformFeaturesAreCurrent;
+
+ reevaluate_platform_features();
+ return launch;
+}
+
+void Application::system_facts_arrived(SystemFacts const& facts)
+{
+ if (facts.probe_failure.has_value()) {
+ warnln("The system probe failed: {}", *facts.probe_failure);
+ // The next launch waits for its probe rather than trusting facts that this one could not confirm.
+ (void)FileSystem::remove(platform_features_cache_path(), FileSystem::RecursionMode::Disallowed);
+ } else if (auto result = write_cached_system_facts(platform_features_cache_path(), facts); result.is_error()) {
+ warnln("Could not cache the system's facts: {}", result.error());
+ }
+
+ m_system_facts = facts;
+ reevaluate_platform_features();
+
+ // A Compositor started from the cached facts is relaunched with the features the system has now.
+ if (m_compositor_client && m_platform_feature_decisions->features_for(FeatureProcess::Compositor).to_byte_string() != m_compositor_launched_features) {
+ dbgln("The Compositor's platform features changed, relaunching it");
+ m_compositor_relaunch_is_planned = true;
+ m_compositor_client->shutdown();
+ }
+
+ auto callbacks = move(m_callbacks_awaiting_current_platform_features);
+ for (auto& callback : callbacks)
+ callback();
+}
+
+void Application::reevaluate_platform_features()
+{
+ m_platform_feature_decisions = PlatformFeatureDecisions::evaluate(m_system_facts, m_feature_overrides, m_feature_runtime_failures);
+}
+
+void Application::when_platform_features_are_current(Function<void()> callback)
+{
+ if (m_system_probe && !m_system_probe->has_finished()) {
+ m_callbacks_awaiting_current_platform_features.append(move(callback));
+ return;
+ }
+ callback();
+}
+
ErrorOr<void> Application::launch_compositor_process()
{
VERIFY(!m_compositor_client);
- m_compositor_client = TRY(WebView::launch_compositor_process());
+ m_compositor_launched_features = m_platform_feature_decisions->features_for(FeatureProcess::Compositor).to_byte_string();
+ m_compositor_client = TRY(WebView::launch_compositor_process(m_compositor_launched_features));
m_compositor_client->on_death = [this]() {
handle_compositor_process_death();
};
@@ -2013,23 +2177,58 @@ void Application::recover_compositor_process()
if (Core::EventLoop::current().was_exit_requested())
return;
- constexpr size_t max_compositor_restart_count = 3;
- if (m_compositor_restart_count >= max_compositor_restart_count) {
- warnln("Compositor process crashed repeatedly, crashing Browser");
- VERIFY_NOT_REACHED();
+ bool counts_as_crash = !exchange(m_compositor_relaunch_is_planned, false);
+
+ // A Compositor started from cached facts may have died of what changed since they were cached, so it is held until
+ // the probe reports. It only counts as a crash if the probe leaves it with the same features.
+ if (counts_as_crash && m_system_probe && !m_system_probe->has_finished()) {
+ when_platform_features_are_current([this] {
+ auto features = m_platform_feature_decisions->features_for(FeatureProcess::Compositor).to_byte_string();
+ relaunch_compositor_process(features == m_compositor_launched_features);
+ });
+ return;
}
- ++m_compositor_restart_count;
- dbgln("Compositor process died, restarting ({}/{})", m_compositor_restart_count, max_compositor_restart_count);
+ relaunch_compositor_process(counts_as_crash);
+}
+
+void Application::relaunch_compositor_process(bool counts_as_crash)
+{
+ if (Core::EventLoop::current().was_exit_requested())
+ return;
+
+ if (counts_as_crash) {
+ constexpr size_t max_compositor_restart_count = 3;
+ if (m_compositor_restart_count >= max_compositor_restart_count) {
+ if (!m_platform_feature_decisions->is_enabled(PlatformFeatures::Feature::GpuPainting)) {
+ warnln("Compositor process crashed repeatedly, crashing Browser");
+ VERIFY_NOT_REACHED();
+ }
+ warnln("Compositor process crashed repeatedly while painting on the GPU, painting on the CPU instead");
+ m_feature_runtime_failures.set(PlatformFeatures::Feature::GpuPainting, "The Compositor crashed repeatedly while painting on the GPU"_string);
+ reevaluate_platform_features();
+ m_compositor_restart_count = 0;
+ }
+
+ ++m_compositor_restart_count;
+ dbgln("Compositor process died, restarting ({}/{})", m_compositor_restart_count, max_compositor_restart_count);
+ }
VERIFY(m_compositor_recovery_state == CompositorRecoveryState::Idle);
m_compositor_recovery_state = CompositorRecoveryState::Recovering;
ScopeGuard clear_recovery_flag = [this] {
m_compositor_recovery_state = CompositorRecoveryState::Idle;
};
+ bring_up_compositor_process();
+}
+
+void Application::bring_up_compositor_process()
+{
+ if (Core::EventLoop::current().was_exit_requested())
+ return;
if (auto result = launch_compositor_process(); result.is_error()) {
- warnln("Unable to restart Compositor process: {}", result.error());
+ warnln("Unable to launch Compositor process: {}", result.error());
VERIFY_NOT_REACHED();
}
diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.h
index 7d6047dc57f..6e7c9a57b8f 100644
--- a/Libraries/LibWebView/Application.h
+++ b/Libraries/LibWebView/Application.h
@@ -54,6 +54,7 @@
#include <LibWebView/FileDownloader.h>
#include <LibWebView/Forward.h>
#include <LibWebView/Options.h>
+#include <LibWebView/PlatformFeatureDecisions.h>
#include <LibWebView/Process.h>
#include <LibWebView/ProcessManager.h>
#include <LibWebView/Profile.h>
@@ -372,6 +373,7 @@ public:
bool devtools_enabled() const { return m_devtools; }
void dump_cookies() const;
void crash_compositor_process();
+ bool has_compositor_process() const { return m_compositor_client; }
FileDownloader& file_downloader() { return m_file_downloader; }
@@ -393,6 +395,9 @@ public:
using CompositorGpuDeviceIdentityCallback = Function<void(Optional<Gfx::GpuDeviceIdentity> const&)>;
void when_compositor_gpu_device_identity_is_known(CompositorGpuDeviceIdentityCallback);
+ // 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()>);
+
protected:
explicit Application(Optional<ByteString> ladybird_binary_path = {});
@@ -436,10 +441,19 @@ private:
ErrorOr<void> launch_services();
void launch_spare_web_content_process();
+ enum class CompositorLaunch {
+ Now,
+ WhenPlatformFeaturesAreCurrent,
+ };
+ CompositorLaunch prepare_platform_features();
+ void system_facts_arrived(SystemFacts const&);
+ void reevaluate_platform_features();
ErrorOr<void> launch_compositor_process();
+ void bring_up_compositor_process();
void compositor_reported_gpu_device_identity(Optional<Gfx::GpuDeviceIdentity>);
void handle_compositor_process_death();
void recover_compositor_process();
+ void relaunch_compositor_process(bool counts_as_crash);
ErrorOr<void> launch_request_server();
ErrorOr<void> launch_devtools_server();
// Returns whether the combined rules changed.
@@ -616,6 +630,18 @@ private:
Optional<Optional<Gfx::GpuDeviceIdentity>> m_compositor_gpu_device_identity;
Vector<CompositorGpuDeviceIdentityCallback> m_callbacks_awaiting_compositor_gpu_device_identity;
size_t m_compositor_restart_count { 0 };
+ // 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;
+
+ FeatureOverrides m_feature_overrides;
+ HashMap<PlatformFeatures::Feature, String> m_feature_runtime_failures;
+ // The facts the decisions were made from, which are the cached ones until the probe reports.
+ SystemFacts m_system_facts;
+ Optional<PlatformFeatureDecisions> m_platform_feature_decisions;
+ OwnPtr<SystemProbeClient> m_system_probe;
+ Vector<Function<void()>> m_callbacks_awaiting_current_platform_features;
+
enum class CompositorRecoveryState {
Idle,
Queued,
diff --git a/Libraries/LibWebView/CMakeLists.txt b/Libraries/LibWebView/CMakeLists.txt
index d040d67740b..9b113aa27b1 100644
--- a/Libraries/LibWebView/CMakeLists.txt
+++ b/Libraries/LibWebView/CMakeLists.txt
@@ -55,6 +55,7 @@ set(SOURCES
PictureInPictureManager.cpp
PictureInPictureWindow.cpp
PermissionManager.cpp
+ PlatformFeatureDecisions.cpp
Process.cpp
ProcessManager.cpp
ProcessSnapshot.cpp
@@ -74,6 +75,7 @@ set(SOURCES
SiteCompatibility.cpp
StorageAreaRegistry.cpp
StorageJar.cpp
+ SystemProbeClient.cpp
TestSpellChecker.cpp
TestTranslator.cpp
Translator.cpp
@@ -168,7 +170,7 @@ add_custom_target(generate_build_information DEPENDS ${build_information_stamp})
ladybird_lib(LibWebView webview EXPLICIT_SYMBOL_EXPORT)
add_dependencies(LibWebView generate_build_information)
-target_link_libraries(LibWebView PUBLIC LibCompositing LibSandbox LibWebCommon)
+target_link_libraries(LibWebView PUBLIC LibCompositing LibPlatformFeatures LibSandbox LibWebCommon)
target_link_libraries(LibWebView PRIVATE LibCore LibCrypto LibDatabase LibDevTools LibFileSystem LibGfx LibHTTP LibImageDecoderClient LibIPC LibRequests LibMedia LibMediaClient LibUnicode LibURL LibTextCodec LibThreading)
if (LINUX)
diff --git a/Libraries/LibWebView/Forward.h b/Libraries/LibWebView/Forward.h
index 9a19ece441a..75a03947645 100644
--- a/Libraries/LibWebView/Forward.h
+++ b/Libraries/LibWebView/Forward.h
@@ -63,6 +63,7 @@ class SettingsUI;
class SpellChecker;
class Translator;
class StorageJar;
+class SystemProbeClient;
class TraversableSessionHistory;
class VideoDecoderServerControlClient;
class ViewImplementation;
diff --git a/Libraries/LibWebView/HelperProcess.cpp b/Libraries/LibWebView/HelperProcess.cpp
index 4cfad72cd30..271f964689d 100644
--- a/Libraries/LibWebView/HelperProcess.cpp
+++ b/Libraries/LibWebView/HelperProcess.cpp
@@ -520,7 +520,7 @@ void shut_down_video_decoder_servers()
s_video_decoder_servers->clear();
}
-ErrorOr<NonnullRefPtr<WebView::CompositorClient>> launch_compositor_process()
+ErrorOr<NonnullRefPtr<WebView::CompositorClient>> launch_compositor_process(ByteString const& platform_features)
{
auto const& browser_options = WebView::Application::browser_options();
auto const& web_content_options = WebView::Application::web_content_options();
@@ -537,8 +537,7 @@ ErrorOr<NonnullRefPtr<WebView::CompositorClient>> launch_compositor_process()
arguments.append("--disable-sandbox"sv);
if (web_content_options.is_test_mode == WebView::IsTestMode::Yes)
arguments.append("--test-mode"sv);
- if (web_content_options.force_cpu_painting == WebView::ForceCPUPainting::Yes)
- arguments.append("--force-cpu-painting"sv);
+ arguments.append(ByteString::formatted("--platform-features={}", platform_features));
if (web_content_options.force_fontconfig == WebView::ForceFontconfig::Yes)
arguments.append("--force-fontconfig"sv);
if (auto gpu_device = WebView::Application::the().platform_presentation_gpu_device(); gpu_device.has_value()) {
diff --git a/Libraries/LibWebView/HelperProcess.h b/Libraries/LibWebView/HelperProcess.h
index 866fa9c2834..e23444dc66f 100644
--- a/Libraries/LibWebView/HelperProcess.h
+++ b/Libraries/LibWebView/HelperProcess.h
@@ -28,7 +28,8 @@ WEBVIEW_API ErrorOr<NonnullRefPtr<MediaClient::Client>> launch_media_server_proc
WEBVIEW_API ErrorOr<NonnullRefPtr<AudioServerControlClient>> launch_audio_server_process(u64 owner_child_id);
WEBVIEW_API ErrorOr<NonnullRefPtr<VideoDecoderServerControlClient>> launch_video_decoder_server_process(u64 owner_child_id, Optional<Gfx::GpuDeviceIdentity> const&);
WEBVIEW_API void shut_down_video_decoder_servers();
-WEBVIEW_API ErrorOr<NonnullRefPtr<WebView::CompositorClient>> launch_compositor_process();
+// The features are the Compositor's own, in the text form of PlatformFeatures::ProcessFeatures.
+WEBVIEW_API ErrorOr<NonnullRefPtr<WebView::CompositorClient>> launch_compositor_process(ByteString const& platform_features);
// Serves the given site's partitions, or all partitions if site is empty.
WEBVIEW_API ErrorOr<NonnullRefPtr<Requests::RequestControlClient>> launch_request_server_process(ByteString const& cache_path, Optional<Utf16String> const& site, HTTPDiskCacheMode);
WEBVIEW_API void apply_dns_settings(Requests::RequestControlClient&);
diff --git a/Libraries/LibWebView/PlatformFeatureDecisions.cpp b/Libraries/LibWebView/PlatformFeatureDecisions.cpp
new file mode 100644
index 00000000000..751068bf72b
--- /dev/null
+++ b/Libraries/LibWebView/PlatformFeatureDecisions.cpp
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWebView/PlatformFeatureDecisions.h>
+
+namespace WebView {
+
+ReadonlySpan<BlocklistRule> blocklist_rules()
+{
+ static constexpr Array<BlocklistRule, 0> rules {};
+ return rules;
+}
+
+static Optional<String> missing_capability(Feature feature, SystemFacts const& facts, PlatformFeatures::Build const& build)
+{
+ switch (feature) {
+ case Feature::GpuPainting:
+ // The probe only describes the GPU through Vulkan, so otherwise the Compositor finds out for itself whether it
+ // can paint on it.
+ if (!build.paints_through_vulkan)
+ return {};
+ if (facts.probe_failure.has_value())
+ return MUST(String::formatted("The system probe failed: {}", *facts.probe_failure));
+ if (!facts.gpu.has_value())
+ return "No Vulkan device was found"_string;
+ return {};
+ case Feature::YCbCrImport:
+ if (!facts.gpu.has_value() || !facts.gpu->supports_ycbcr_sampling)
+ return "The GPU does not support YCbCr sampling"_string;
+ return {};
+ }
+ VERIFY_NOT_REACHED();
+}
+
+StringView feature_state_name(FeatureStatus::State state)
+{
+ switch (state) {
+ case FeatureStatus::State::Enabled:
+ return "Enabled"sv;
+ case FeatureStatus::State::Unsupported:
+ return "Unsupported"sv;
+ case FeatureStatus::State::Blocklisted:
+ return "Blocklisted"sv;
+ case FeatureStatus::State::DisabledByUser:
+ return "Disabled by user"sv;
+ case FeatureStatus::State::BlockedByDependency:
+ return "Blocked by dependency"sv;
+ case FeatureStatus::State::FailedAtRuntime:
+ return "Failed at runtime"sv;
+ case FeatureStatus::State::NotBuilt:
+ return "Not built"sv;
+ }
+ VERIFY_NOT_REACHED();
+}
+
+PlatformFeatureDecisions PlatformFeatureDecisions::evaluate(SystemFacts const& facts, FeatureOverrides const& overrides, HashMap<Feature, String> const& runtime_failures, ReadonlySpan<BlocklistRule> rules, PlatformFeatures::Build const& build)
+{
+ PlatformFeatureDecisions decisions;
+
+ // Every dependency is declared before the features that depend on it, so it has been decided by the time they are.
+ for (auto feature : PlatformFeatures::all_features) {
+ auto& status = decisions.m_statuses[to_underlying(feature)];
+
+ if (!build.includes(feature)) {
+ status.state = FeatureStatus::State::NotBuilt;
+ continue;
+ }
+
+ if (auto dependency = PlatformFeatures::dependency_of(feature); dependency.has_value()) {
+ VERIFY(to_underlying(*dependency) < to_underlying(feature));
+ auto const& dependency_status = decisions.status_of(*dependency);
+ if (dependency_status.state != FeatureStatus::State::Enabled) {
+ status.state = FeatureStatus::State::BlockedByDependency;
+ status.blocking_feature = dependency_status.blocking_feature.value_or(*dependency);
+ continue;
+ }
+ }
+
+ if (auto capability = missing_capability(feature, facts, build); capability.has_value()) {
+ status.state = FeatureStatus::State::Unsupported;
+ status.reason = capability.release_value();
+ continue;
+ }
+
+ if (auto failure = runtime_failures.get(feature); failure.has_value()) {
+ status.state = FeatureStatus::State::FailedAtRuntime;
+ status.reason = *failure;
+ continue;
+ }
+
+ BlocklistRule const* matching_rule = nullptr;
+ for (auto const& rule : rules) {
+ if (rule.feature == feature && rule.matches(facts)) {
+ matching_rule = &rule;
+ break;
+ }
+ }
+
+ // The rule is kept whatever the overrides decide, so that reports say which way the blocklist went.
+ if (matching_rule != nullptr) {
+ status.rule_id = matching_rule->id;
+ status.reason = MUST(String::from_utf8(matching_rule->description));
+ }
+
+ if (overrides.force_enabled.contains(feature)) {
+ status.forced = matching_rule != nullptr || overrides.disabled.contains(feature);
+ if (matching_rule == nullptr && overrides.disabled.contains(feature))
+ status.reason = "Overrides --disable-features"_string;
+ continue;
+ }
+
+ if (overrides.disabled.contains(feature)) {
+ status.state = FeatureStatus::State::DisabledByUser;
+ continue;
+ }
+
+ if (matching_rule != nullptr)
+ status.state = FeatureStatus::State::Blocklisted;
+ }
+
+ return decisions;
+}
+
+bool PlatformFeatureDecisions::decides_without_facts(FeatureProcess process, FeatureOverrides const& overrides, PlatformFeatures::Build const& build)
+{
+ // A process waits for the probe unless the overrides alone turn off each of its features, directly or through a
+ // dependency that is off.
+ for (auto feature : PlatformFeatures::all_features) {
+ if (PlatformFeatures::process_of(feature) != process || !build.includes(feature))
+ continue;
+ auto is_turned_off = [&](Feature candidate) {
+ return overrides.disabled.contains(candidate) && !overrides.force_enabled.contains(candidate);
+ };
+ bool turned_off = is_turned_off(feature);
+ for (auto dependency = PlatformFeatures::dependency_of(feature); !turned_off && dependency.has_value(); dependency = PlatformFeatures::dependency_of(*dependency))
+ turned_off = is_turned_off(*dependency);
+ if (!turned_off)
+ return false;
+ }
+ return true;
+}
+
+PlatformFeatures::ProcessFeatures PlatformFeatureDecisions::features_for(FeatureProcess process) const
+{
+ PlatformFeatures::ProcessFeatures features { process };
+ for (auto feature : PlatformFeatures::all_features) {
+ if (PlatformFeatures::process_of(feature) == process && is_enabled(feature))
+ features.set_enabled(feature);
+ }
+ return features;
+}
+
+}
diff --git a/Libraries/LibWebView/PlatformFeatureDecisions.h b/Libraries/LibWebView/PlatformFeatureDecisions.h
new file mode 100644
index 00000000000..c18b223ea05
--- /dev/null
+++ b/Libraries/LibWebView/PlatformFeatureDecisions.h
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Array.h>
+#include <AK/HashMap.h>
+#include <AK/HashTable.h>
+#include <AK/String.h>
+#include <LibPlatformFeatures/Build.h>
+#include <LibPlatformFeatures/Feature.h>
+#include <LibPlatformFeatures/ProcessFeatures.h>
+#include <LibPlatformFeatures/SystemFacts.h>
+#include <LibWebView/Export.h>
+
+namespace WebView {
+
+using PlatformFeatures::Feature;
+using PlatformFeatures::FeatureProcess;
+using PlatformFeatures::SystemFacts;
+
+// A feature that a driver or library claims to support, but which misbehaves under the conditions it matches.
+struct BlocklistRule {
+ StringView id;
+ Feature feature;
+ StringView description;
+ bool (*matches)(SystemFacts const&);
+};
+
+WEBVIEW_API ReadonlySpan<BlocklistRule> blocklist_rules();
+
+struct FeatureOverrides {
+ HashTable<Feature> disabled;
+ // Overrides the blocklist and the disabled set, but not a missing capability or a dependency that is off.
+ HashTable<Feature> force_enabled;
+};
+
+struct FeatureStatus {
+ enum class State : u8 {
+ Enabled,
+ Unsupported,
+ Blocklisted,
+ DisabledByUser,
+ BlockedByDependency,
+ FailedAtRuntime,
+ // Not part of this build at all, so it is left out wherever features are listed.
+ NotBuilt,
+ };
+
+ State state { State::Enabled };
+ // What the state alone does not say: the missing capability, the failure, the rule that matched, or what forcing
+ // overrode.
+ String reason;
+ // Set when a rule matched, even if the feature was disabled or forced on regardless.
+ StringView rule_id;
+ // Whether --force-enable-features turned the feature on past a rule or a disable.
+ bool forced { false };
+ // The feature whose own state turned this one off, when blocked by a dependency.
+ Optional<Feature> blocking_feature;
+};
+
+WEBVIEW_API StringView feature_state_name(FeatureStatus::State);
+
+class WEBVIEW_API PlatformFeatureDecisions {
+public:
+ static PlatformFeatureDecisions evaluate(SystemFacts const&, FeatureOverrides const&, HashMap<Feature, String> const& runtime_failures, ReadonlySpan<BlocklistRule> = blocklist_rules(), PlatformFeatures::Build const& = PlatformFeatures::this_build);
+ // Whether the overrides alone decide every feature of the process, so that it need not wait for the probe.
+ static bool decides_without_facts(FeatureProcess, FeatureOverrides const&, PlatformFeatures::Build const& = PlatformFeatures::this_build);
+
+ FeatureStatus const& status_of(Feature feature) const { return m_statuses[to_underlying(feature)]; }
+ bool is_enabled(Feature feature) const { return status_of(feature).state == FeatureStatus::State::Enabled; }
+
+ PlatformFeatures::ProcessFeatures features_for(FeatureProcess) const;
+
+private:
+ Array<FeatureStatus, PlatformFeatures::all_features.size()> m_statuses;
+};
+
+}
+
+template<>
+struct AK::Formatter<WebView::FeatureStatus::State> : Formatter<StringView> {
+ ErrorOr<void> format(FormatBuilder& builder, WebView::FeatureStatus::State state)
+ {
+ return Formatter<StringView>::format(builder, WebView::feature_state_name(state));
+ }
+};
diff --git a/Libraries/LibWebView/SystemProbeClient.cpp b/Libraries/LibWebView/SystemProbeClient.cpp
new file mode 100644
index 00000000000..c42886933ce
--- /dev/null
+++ b/Libraries/LibWebView/SystemProbeClient.cpp
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibCore/File.h>
+#include <LibCore/Notifier.h>
+#include <LibCore/Process.h>
+#include <LibCore/System.h>
+#include <LibCore/Timer.h>
+#include <LibFileSystem/FileSystem.h>
+#include <LibWebCommon/WebView/Utilities.h>
+#include <LibWebView/Process.h>
+#include <LibWebView/SystemProbeClient.h>
+
+namespace WebView {
+
+static ErrorOr<Core::Process> spawn_probe(Optional<Gfx::GpuDeviceIdentity> const& presentation_device, int output_fd)
+{
+ Vector<ByteString> arguments;
+ if (presentation_device.has_value()) {
+ arguments.append("--gpu-device"sv);
+ arguments.append(presentation_device->to_byte_string());
+ }
+
+ Core::ProcessSpawnOptions options { .name = "SystemProbe"sv };
+ options.arguments = arguments;
+ options.file_actions.append(Core::FileAction::DupFd { .write_fd = output_fd, .fd = STDOUT_FILENO });
+
+ for (auto const& path : TRY(get_paths_for_helper_process("SystemProbe"sv))) {
+ if (!FileSystem::exists(path))
+ continue;
+ options.executable = path;
+ // The probe loads the driver as the Compositor will, so it sees the same environment.
+ return Process::spawn_without_transport(ProcessType::Compositor, options);
+ }
+ return Error::from_string_literal("The SystemProbe helper was not found");
+}
+
+NonnullOwnPtr<SystemProbeClient> SystemProbeClient::launch(Optional<Gfx::GpuDeviceIdentity> const& presentation_device, Function<void(PlatformFeatures::SystemFacts const&)> on_finish)
+{
+ auto client_owner = adopt_own(*new SystemProbeClient);
+ auto& client = *client_owner;
+ client.m_on_finish = move(on_finish);
+
+ auto pipe = Core::System::pipe2(O_CLOEXEC);
+ if (pipe.is_error()) {
+ client.fail("Could not create a pipe for its report"sv);
+ return client_owner;
+ }
+ auto output = Core::File::adopt_fd(pipe.value()[0], Core::File::OpenMode::Read);
+ if (output.is_error()) {
+ (void)Core::System::close(pipe.value()[0]);
+ (void)Core::System::close(pipe.value()[1]);
+ client.fail("Could not create a pipe for its report"sv);
+ return client_owner;
+ }
+ client.m_output = output.release_value();
+
+ auto process = spawn_probe(presentation_device, pipe.value()[1]);
+ (void)Core::System::close(pipe.value()[1]);
+ if (process.is_error()) {
+ client.fail("It could not be launched"sv);
+ return client_owner;
+ }
+
+ client.m_pid = process.value().pid();
+ client.m_notifier = Core::Notifier::construct(client.m_output->fd(), Core::Notifier::Type::Read);
+ client.m_notifier->on_activation = [&client] {
+ client.read_available_output();
+ };
+ client.m_timeout_timer = Core::Timer::create_single_shot(timeout, [&client] {
+ client.fail("It did not report in time"sv);
+ });
+ client.m_timeout_timer->start();
+ return client_owner;
+}
+
+SystemProbeClient::~SystemProbeClient()
+{
+ if (!has_finished())
+ terminate_probe();
+}
+
+void SystemProbeClient::read_available_output()
+{
+ Array<u8, 4 * KiB> buffer;
+ auto result = m_output->read_some(buffer);
+ if (result.is_error()) {
+ if (result.error().is_errno() && (result.error().code() == EINTR || result.error().code() == EAGAIN))
+ return;
+ fail("Its report could not be read"sv);
+ return;
+ }
+ auto bytes_read = result.value().size();
+ if (bytes_read == 0) {
+ finish_with_report();
+ return;
+ }
+ if (m_report.size() + bytes_read > maximum_report_size) {
+ fail("Its report was too large"sv);
+ return;
+ }
+ m_report.append(result.value());
+}
+
+void SystemProbeClient::finish_with_report()
+{
+ auto facts = PlatformFeatures::SystemFacts::from_json(StringView { m_report.bytes() });
+ if (facts.is_error()) {
+ // A probe that died before reporting closed its output just the same.
+ fail(m_report.is_empty() ? "It exited without a report"sv : "Its report could not be understood"sv);
+ return;
+ }
+ finish(facts.release_value());
+}
+
+void SystemProbeClient::fail(StringView reason)
+{
+ terminate_probe();
+ PlatformFeatures::SystemFacts facts;
+ facts.probe_failure = MUST(String::from_utf8(reason));
+ finish(move(facts));
+}
+
+void SystemProbeClient::finish(PlatformFeatures::SystemFacts facts)
+{
+ if (has_finished())
+ return;
+ m_facts = move(facts);
+ stop_reading();
+
+ if (m_on_finish)
+ m_on_finish(*m_facts);
+}
+
+void SystemProbeClient::terminate_probe()
+{
+ if (m_pid > 0)
+ (void)Core::Process::terminate_process(m_pid, Core::Process::TerminationMode::Forceful);
+ stop_reading();
+}
+
+void SystemProbeClient::stop_reading()
+{
+ if (m_notifier) {
+ m_notifier->close();
+ m_notifier = nullptr;
+ }
+ if (m_timeout_timer) {
+ m_timeout_timer->stop();
+ m_timeout_timer = nullptr;
+ }
+ m_output = nullptr;
+ // The ProcessMonitor reaps the probe along with every other child.
+ m_pid = -1;
+}
+
+}
diff --git a/Libraries/LibWebView/SystemProbeClient.h b/Libraries/LibWebView/SystemProbeClient.h
new file mode 100644
index 00000000000..cf2f876c2c1
--- /dev/null
+++ b/Libraries/LibWebView/SystemProbeClient.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/ByteBuffer.h>
+#include <AK/Function.h>
+#include <AK/NonnullOwnPtr.h>
+#include <AK/OwnPtr.h>
+#include <AK/RefPtr.h>
+#include <AK/Time.h>
+#include <LibCore/Forward.h>
+#include <LibGfx/GpuDeviceIdentity.h>
+#include <LibPlatformFeatures/SystemFacts.h>
+#include <LibWebView/Export.h>
+
+namespace WebView {
+
+// Runs the SystemProbe helper once and reads the facts it reports. A probe that crashes, hangs or reports something
+// unreadable yields facts that say so, rather than an error.
+class WEBVIEW_API SystemProbeClient {
+ AK_MAKE_NONCOPYABLE(SystemProbeClient);
+ AK_MAKE_NONMOVABLE(SystemProbeClient);
+
+public:
+ AK_ALLOC_WITH_KMALLOC;
+
+ static constexpr AK::Duration timeout = AK::Duration::from_seconds(4);
+ static constexpr size_t maximum_report_size = 64 * KiB;
+
+ // Destroying the client before the probe reports stops the probe without calling on_finish.
+ static NonnullOwnPtr<SystemProbeClient> launch(Optional<Gfx::GpuDeviceIdentity> const& presentation_device, Function<void(PlatformFeatures::SystemFacts const&)> on_finish);
+
+ ~SystemProbeClient();
+
+ bool has_finished() const { return m_facts.has_value(); }
+
+private:
+ SystemProbeClient() = default;
+
+ void read_available_output();
+ void finish_with_report();
+ void finish(PlatformFeatures::SystemFacts);
+ void terminate_probe();
+ void stop_reading();
+ void fail(StringView reason);
+
+ pid_t m_pid { -1 };
+ OwnPtr<Core::File> m_output;
+ RefPtr<Core::Notifier> m_notifier;
+ RefPtr<Core::Timer> m_timeout_timer;
+ ByteBuffer m_report;
+ Optional<PlatformFeatures::SystemFacts> m_facts;
+ // Called once, from launch() or from the event loop.
+ Function<void(PlatformFeatures::SystemFacts const&)> m_on_finish;
+};
+
+}
diff --git a/Meta/CMake/ladybird_helper_processes.cmake b/Meta/CMake/ladybird_helper_processes.cmake
index 8e74cbf9f99..0476a8e5e69 100644
--- a/Meta/CMake/ladybird_helper_processes.cmake
+++ b/Meta/CMake/ladybird_helper_processes.cmake
@@ -5,6 +5,7 @@ set(ladybird_helper_processes
ImageDecoder
MediaServer
RequestServer
+ SystemProbe
VideoDecoderServer
WebContent
WebRTCClient
diff --git a/Services/CMakeLists.txt b/Services/CMakeLists.txt
index 0b93a50f176..f278bddabd5 100644
--- a/Services/CMakeLists.txt
+++ b/Services/CMakeLists.txt
@@ -7,6 +7,7 @@ if (APPLE)
add_subdirectory(ProcessReaper)
endif()
add_subdirectory(RequestServer)
+add_subdirectory(SystemProbe)
add_subdirectory(VideoDecoderServer)
add_subdirectory(WebContent)
add_subdirectory(WebDriver)
diff --git a/Services/Compositor/CMakeLists.txt b/Services/Compositor/CMakeLists.txt
index 0281ffbe6c6..893793a09ad 100644
--- a/Services/Compositor/CMakeLists.txt
+++ b/Services/Compositor/CMakeLists.txt
@@ -77,7 +77,7 @@ endif()
target_include_directories(compositorservice PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../..)
target_include_directories(compositorservice PRIVATE ${LADYBIRD_SOURCE_DIR}/Services/)
-target_link_libraries(Compositor PRIVATE compositorservice LibCore LibGfx LibMain LibSandbox)
+target_link_libraries(Compositor PRIVATE compositorservice LibCore LibGfx LibMain LibPlatformFeatures LibSandbox)
# ANGLE must precede Skia so macOS GLES symbols bind to ANGLE rather than the
# OpenGL framework pulled in by Skia.
target_link_libraries(compositorservice PRIVATE LibCore LibGfx LibImageDecoderClient LibIPC LibMedia LibCompositing compositor_core ${ANGLE_TARGETS} skia)
diff --git a/Services/Compositor/main.cpp b/Services/Compositor/main.cpp
index f3ebd490784..d367268105f 100644
--- a/Services/Compositor/main.cpp
+++ b/Services/Compositor/main.cpp
@@ -22,6 +22,7 @@
#include <LibGfx/GpuDeviceIdentity.h>
#include <LibIPC/SingleServer.h>
#include <LibMain/Main.h>
+#include <LibPlatformFeatures/ProcessFeatures.h>
ErrorOr<int> ladybird_main(Main::Arguments arguments)
{
@@ -32,7 +33,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
StringView resource_root;
bool wait_for_debugger = false;
bool enable_test_mode = false;
- bool force_cpu_painting = false;
+ StringView platform_features;
bool force_fontconfig = false;
bool disable_sandbox = false;
StringView gpu_device;
@@ -47,7 +48,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
args_parser.add_option(resource_root, "Path to the browser's resources", "resource-root", 0, "path");
args_parser.add_option(wait_for_debugger, "Wait for debugger", "wait-for-debugger");
args_parser.add_option(enable_test_mode, "Enable test mode", "test-mode");
- args_parser.add_option(force_cpu_painting, "Force CPU painting", "force-cpu-painting");
+ args_parser.add_option(platform_features, "The platform features the Browser decided this process may use", "platform-features", 0, "feature,...");
args_parser.add_option(force_fontconfig, "Force using fontconfig for font loading", "force-fontconfig");
args_parser.add_option(disable_sandbox, "Disable process sandboxing", "disable-sandbox");
args_parser.add_option(gpu_device, "The GPU to paint on, as the presentation identifies it", "gpu-device", 0, "identity");
@@ -60,6 +61,9 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
if (resource_root.is_empty())
return Error::from_string_literal("--resource-root is required");
+ PlatformFeatures::ProcessFeatures::initialize_for_current_process(TRY(PlatformFeatures::ProcessFeatures::from_string(PlatformFeatures::FeatureProcess::Compositor, platform_features)));
+ auto const& features = PlatformFeatures::ProcessFeatures::the();
+
Optional<Gfx::GpuDeviceIdentity> preferred_gpu_device;
if (!gpu_device.is_empty()) {
preferred_gpu_device = Gfx::GpuDeviceIdentity::from_string(gpu_device);
@@ -105,7 +109,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
TRY(Compositor::restrict_filesystem(resource_root));
#endif
- if (!force_cpu_painting)
+ if (features.is_enabled(PlatformFeatures::Feature::GpuPainting))
Gfx::SkiaBackendContext::initialize_gpu_backend(preferred_gpu_device);
auto skia_backend_context = Gfx::SkiaBackendContext::the_main_thread_context();
@@ -120,7 +124,8 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
Optional<Gfx::GpuDeviceIdentity> gpu_device_identity;
#ifdef USE_VULKAN_DMABUF_IMAGES
- if (skia_backend_context && skia_backend_context->vulkan_context().can_sample_through_ycbcr_conversion)
+ // Hardware decoding only starts once the GPU it decodes on is named, which is only done when its frames can be imported.
+ if (skia_backend_context && features.is_enabled(PlatformFeatures::Feature::YCbCrImport) && skia_backend_context->vulkan_context().can_sample_through_ycbcr_conversion)
gpu_device_identity = skia_backend_context->vulkan_context().device_identity;
#endif
diff --git a/Services/SystemProbe/CMakeLists.txt b/Services/SystemProbe/CMakeLists.txt
new file mode 100644
index 00000000000..028228e4dd5
--- /dev/null
+++ b/Services/SystemProbe/CMakeLists.txt
@@ -0,0 +1,17 @@
+set(SOURCES
+ main.cpp
+)
+
+if (HAS_VULKAN)
+ list(APPEND SOURCES VulkanDescription.cpp)
+endif()
+
+add_executable(SystemProbe ${SOURCES})
+
+target_include_directories(SystemProbe PRIVATE ${LADYBIRD_SOURCE_DIR}/Services/)
+target_link_libraries(SystemProbe PRIVATE LibCore LibGfx LibMain LibPlatformFeatures)
+if (HAS_VULKAN)
+ target_link_libraries(SystemProbe PRIVATE Vulkan::Vulkan)
+endif()
+
+ladybird_sign_helper_process(SystemProbe)
diff --git a/Services/SystemProbe/VulkanDescription.cpp b/Services/SystemProbe/VulkanDescription.cpp
new file mode 100644
index 00000000000..827e20a7b6d
--- /dev/null
+++ b/Services/SystemProbe/VulkanDescription.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibGfx/VulkanContext.h>
+#include <SystemProbe/VulkanDescription.h>
+#include <string.h>
+
+static String string_from_driver(char const* characters, size_t capacity)
+{
+ return String::from_utf8_with_replacement_character({ characters, strnlen(characters, capacity) });
+}
+
+Optional<PlatformFeatures::GpuFacts> describe_gpu_through_vulkan(Optional<Gfx::GpuDeviceIdentity> const& preferred_device)
+{
+ VkApplicationInfo application_info {};
+ application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
+ application_info.pApplicationName = "Ladybird";
+ application_info.apiVersion = VK_API_VERSION_1_3;
+
+ VkInstanceCreateInfo instance_info {};
+ instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
+ instance_info.pApplicationInfo = &application_info;
+
+ // The instance is never destroyed, since tearing the driver down only delays the exit.
+ VkInstance instance = VK_NULL_HANDLE;
+ if (vkCreateInstance(&instance_info, nullptr, &instance) != VK_SUCCESS)
+ return {};
+
+ auto physical_device = Gfx::pick_physical_device(instance, preferred_device);
+ if (physical_device.is_error())
+ return {};
+
+ VkPhysicalDeviceProperties basic_properties;
+ vkGetPhysicalDeviceProperties(physical_device.value(), &basic_properties);
+
+ VkPhysicalDeviceDriverProperties driver_properties {};
+ driver_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES;
+ VkPhysicalDeviceProperties2 properties {};
+ properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
+ // Drivers describe themselves from Vulkan 1.2.
+ if (basic_properties.apiVersion >= VK_API_VERSION_1_2)
+ properties.pNext = &driver_properties;
+ vkGetPhysicalDeviceProperties2(physical_device.value(), &properties);
+
+ PlatformFeatures::GpuFacts gpu;
+ gpu.vendor_id = properties.properties.vendorID;
+ gpu.device_id = properties.properties.deviceID;
+ gpu.device_name = string_from_driver(properties.properties.deviceName, sizeof(properties.properties.deviceName));
+ gpu.driver_id = driver_properties.driverID;
+ gpu.driver_name = string_from_driver(driver_properties.driverName, sizeof(driver_properties.driverName));
+ gpu.driver_info = string_from_driver(driver_properties.driverInfo, sizeof(driver_properties.driverInfo));
+ gpu.driver_version = properties.properties.driverVersion;
+ gpu.api_version = properties.properties.apiVersion;
+ gpu.device_identity = MUST(String::from_byte_string(Gfx::gpu_device_identity_of(physical_device.value()).to_byte_string()));
+ gpu.supports_ycbcr_sampling = Gfx::device_can_sample_through_ycbcr_conversion(physical_device.value());
+ return gpu;
+}
diff --git a/Services/SystemProbe/VulkanDescription.h b/Services/SystemProbe/VulkanDescription.h
new file mode 100644
index 00000000000..1771e87e110
--- /dev/null
+++ b/Services/SystemProbe/VulkanDescription.h
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Optional.h>
+#include <LibGfx/GpuDeviceIdentity.h>
+#include <LibPlatformFeatures/SystemFacts.h>
+
+// Only builds that paint through Vulkan define these.
+Optional<PlatformFeatures::GpuFacts> describe_gpu_through_vulkan(Optional<Gfx::GpuDeviceIdentity> const& preferred_device);
diff --git a/Services/SystemProbe/main.cpp b/Services/SystemProbe/main.cpp
new file mode 100644
index 00000000000..ccfc5c7f725
--- /dev/null
+++ b/Services/SystemProbe/main.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibCore/ArgsParser.h>
+#include <LibCore/File.h>
+#include <LibGfx/GpuDeviceIdentity.h>
+#include <LibMain/Main.h>
+#include <LibPlatformFeatures/Build.h>
+#include <LibPlatformFeatures/SystemFacts.h>
+#include <SystemProbe/VulkanDescription.h>
+
+// Describes the system for the Browser's feature blocklist, and exits. It takes nothing but its arguments and writes
+// nothing but its report, so that it can run with the GPU driver loaded and no sandbox.
+
+ErrorOr<int> ladybird_main(Main::Arguments arguments)
+{
+ StringView gpu_device;
+
+ Core::ArgsParser args_parser;
+ args_parser.add_option(gpu_device, "The GPU that presents, as the presentation identifies it", "gpu-device", 0, "identity");
+ args_parser.parse(arguments);
+
+ Optional<Gfx::GpuDeviceIdentity> preferred_device;
+ if (!gpu_device.is_empty()) {
+ preferred_device = Gfx::GpuDeviceIdentity::from_string(gpu_device);
+ if (!preferred_device.has_value())
+ return Error::from_string_literal("Malformed GPU device identity");
+ }
+
+ PlatformFeatures::SystemFacts facts;
+ if constexpr (PlatformFeatures::this_build.paints_through_vulkan)
+ facts.gpu = describe_gpu_through_vulkan(preferred_device);
+
+ auto report = facts.to_json().serialized();
+ auto output = TRY(Core::File::standard_output());
+ TRY(output->write_until_depleted(report.bytes()));
+
+ // Closing the output ends the report, so the Browser does not wait for the driver to unload as the probe exits.
+ output->close();
+ return 0;
+}
diff --git a/Tests/LibWebView/CMakeLists.txt b/Tests/LibWebView/CMakeLists.txt
index ea81bea6a9a..1b00fc0f924 100644
--- a/Tests/LibWebView/CMakeLists.txt
+++ b/Tests/LibWebView/CMakeLists.txt
@@ -74,6 +74,7 @@ set(TEST_SOURCES
TestOmnibox.cpp
TestPermissionManager.cpp
TestPictureInPictureWindow.cpp
+ TestPlatformFeatures.cpp
TestProfile.cpp
TestSessionHistory.cpp
TestSessionHistoryTraversalQueue.cpp
@@ -130,6 +131,7 @@ if (NOT WIN32)
TestAutocomplete.cpp
TestBeforeUnload.cpp
TestBrowserHistoryTraversal.cpp
+ TestCompositorStartup.cpp
TestCrashOverlay.cpp
TestCrashReportSubmission.cpp
TestFavicon.cpp
diff --git a/Tests/LibWebView/HeadlessTest.h b/Tests/LibWebView/HeadlessTest.h
index 49b03d5579c..45a14cb4f42 100644
--- a/Tests/LibWebView/HeadlessTest.h
+++ b/Tests/LibWebView/HeadlessTest.h
@@ -6,7 +6,7 @@
#pragma once
-#include <AK/Array.h>
+#include <AK/Vector.h>
#include <LibCore/EventLoop.h>
#include <LibWebView/Application.h>
@@ -35,8 +35,11 @@ public:
ByteString const& directory() const { return m_directory; }
template<typename ApplicationType = HeadlessApplication>
- ErrorOr<NonnullOwnPtr<ApplicationType>> create_application()
+ ErrorOr<NonnullOwnPtr<ApplicationType>> create_application(ReadonlySpan<StringView> extra_arguments = {})
{
+ // The application keeps the arguments it is created with.
+ m_arguments.shrink(1);
+ m_arguments.append(extra_arguments.data(), extra_arguments.size());
return ApplicationType::create({ .strings = m_arguments }, ladybird_binary_path());
}
@@ -44,7 +47,7 @@ private:
static Optional<ByteString> ladybird_binary_path();
ByteString m_directory;
- Array<StringView, 1> m_arguments { "TestLibWebView"sv };
+ Vector<StringView, 2> m_arguments { "TestLibWebView"sv };
Core::EventLoop m_event_loop;
};
diff --git a/Tests/LibWebView/TestCompositorStartup.cpp b/Tests/LibWebView/TestCompositorStartup.cpp
new file mode 100644
index 00000000000..6a051d8f2c7
--- /dev/null
+++ b/Tests/LibWebView/TestCompositorStartup.cpp
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include "HeadlessTest.h"
+#include <AK/Array.h>
+#include <AK/LexicalPath.h>
+#include <LibCore/EventLoop.h>
+#include <LibCore/File.h>
+#include <LibFileSystem/FileSystem.h>
+#include <LibGfx/SystemTheme.h>
+#include <LibTest/TestCase.h>
+#include <LibURL/Parser.h>
+#include <LibURL/URL.h>
+#include <LibWebView/Application.h>
+#include <LibWebView/HeadlessWebView.h>
+#include <LibWebView/Utilities.h>
+
+namespace {
+
+class TestApplication : public Test::HeadlessApplication {
+ WEB_VIEW_APPLICATION(TestApplication)
+
+public:
+ explicit TestApplication(Optional<ByteString> ladybird_binary_path)
+ : Test::HeadlessApplication(move(ladybird_binary_path))
+ {
+ }
+
+ virtual void create_platform_options(WebView::BrowserOptions& browser_options, WebView::RequestServerOptions&, WebView::WebContentOptions& web_content_options) override
+ {
+ browser_options.headless_mode.clear();
+ browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;
+ // Outside test mode, the Compositor is launched from what the system probe reports.
+ web_content_options.is_test_mode = WebView::IsTestMode::No;
+ }
+};
+
+}
+
+TEST_CASE(a_tab_opened_before_the_compositor_launches_paints_once_it_does)
+{
+ Test::HeadlessTestEnvironment environment { "TestCompositorStartup"sv };
+ // A temporary profile has no facts cached by an earlier probe, so the Compositor waits for this one.
+ Array arguments { "--temporary-profile"sv };
+ auto app = TRY_OR_FAIL(environment.create_application<TestApplication>(arguments));
+ EXPECT(!app->has_compositor_process());
+
+ auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);
+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));
+ auto view = WebView::HeadlessWebView::create(theme, { 800, 600 });
+ EXPECT(!app->has_compositor_process());
+
+ bool painted = false;
+ view->on_ready_to_paint = [&] { painted = true; };
+ view->load(URL::Parser::basic_parse("data:text/html,<p>painted"sv).release_value());
+ Core::EventLoop::current().spin_until([&] { return painted; });
+ view->on_ready_to_paint = nullptr;
+
+ EXPECT(app->has_compositor_process());
+}
+
+TEST_CASE(a_video_that_starts_before_the_compositor_launches_plays_once_it_does)
+{
+ Test::HeadlessTestEnvironment environment { "TestCompositorStartup"sv };
+ Array arguments { "--temporary-profile"sv, "--enable-autoplay"sv };
+ auto app = TRY_OR_FAIL(environment.create_application<TestApplication>(arguments));
+
+ // The tests run from this directory.
+ auto video_path = TRY_OR_FAIL(FileSystem::real_path("../LibWeb/Assets/blue-with-second-in-gray-64x36.webm"sv));
+ auto page_path = LexicalPath::join(environment.directory(), "video.html"sv).string();
+ auto page = TRY_OR_FAIL(Core::File::open(page_path, Core::File::OpenMode::Write));
+ TRY_OR_FAIL(page->write_formatted("<video autoplay muted src=\"{}\" oncanplay=\"document.title = 'canplay'\"></video>", URL::create_with_file_scheme(video_path)->serialize()));
+ page->close();
+
+ auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);
+ auto theme = TRY_OR_FAIL(Gfx::load_system_theme(theme_path.string()));
+ auto view = WebView::HeadlessWebView::create(theme, { 800, 600 });
+
+ bool can_play = false;
+ view->on_title_change = [&](auto const& title) { can_play = title == "canplay"sv; };
+ view->load(URL::create_with_file_scheme(page_path).release_value());
+ EXPECT(!app->has_compositor_process());
+ Core::EventLoop::current().spin_until([&] { return can_play; });
+ view->on_title_change = nullptr;
+}
diff --git a/Tests/LibWebView/TestPlatformFeatures.cpp b/Tests/LibWebView/TestPlatformFeatures.cpp
new file mode 100644
index 00000000000..f8b77f4e28d
--- /dev/null
+++ b/Tests/LibWebView/TestPlatformFeatures.cpp
@@ -0,0 +1,252 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibTest/TestCase.h>
+#include <LibWebView/PlatformFeatureDecisions.h>
+
+using PlatformFeatures::Build;
+using PlatformFeatures::GpuFacts;
+using PlatformFeatures::ProcessFeatures;
+using WebView::BlocklistRule;
+using WebView::Feature;
+using WebView::FeatureOverrides;
+using WebView::FeatureProcess;
+using WebView::FeatureStatus;
+using WebView::PlatformFeatureDecisions;
+using WebView::SystemFacts;
+
+static SystemFacts facts_with_a_gpu()
+{
+ GpuFacts gpu;
+ gpu.vendor_id = 0x10de;
+ gpu.device_id = 0x2204;
+ gpu.device_name = "NVIDIA GeForce RTX 3090"_string;
+ gpu.driver_id = 4;
+ gpu.driver_name = "NVIDIA"_string;
+ gpu.driver_info = "615.78.08"_string;
+ gpu.driver_version = 0x99e3a200;
+ gpu.api_version = 0x4040df;
+ gpu.device_identity = "7709ab0ea273f34e0bb993d4328b5309"_string;
+ gpu.supports_ycbcr_sampling = true;
+
+ SystemFacts facts;
+ facts.gpu = move(gpu);
+ return facts;
+}
+
+static bool matches_nvidia(SystemFacts const& facts)
+{
+ return facts.gpu.has_value() && facts.gpu->vendor_id == 0x10de;
+}
+
+static constexpr Array test_rules {
+ BlocklistRule { "test-nvidia-ycbcr"sv, Feature::YCbCrImport, "NVIDIA cannot import video, for this test"sv, matches_nvidia },
+};
+
+static PlatformFeatureDecisions evaluate(SystemFacts const& facts, FeatureOverrides const& overrides = {}, HashMap<Feature, String> const& runtime_failures = {})
+{
+ return PlatformFeatureDecisions::evaluate(facts, overrides, runtime_failures, test_rules, Build::with_every_feature());
+}
+
+TEST_CASE(every_dependency_is_declared_before_its_dependents)
+{
+ for (auto feature : PlatformFeatures::all_features) {
+ if (auto dependency = PlatformFeatures::dependency_of(feature); dependency.has_value())
+ EXPECT(to_underlying(*dependency) < to_underlying(feature));
+ EXPECT_EQ(PlatformFeatures::feature_from_id(PlatformFeatures::feature_id(feature)), feature);
+ }
+}
+
+TEST_CASE(a_build_includes_the_dependency_of_every_feature_it_includes)
+{
+ for (auto const& build : { PlatformFeatures::this_build, Build::with_every_feature(), Build {} }) {
+ for (auto feature : PlatformFeatures::all_features) {
+ if (auto dependency = PlatformFeatures::dependency_of(feature); dependency.has_value() && build.includes(feature))
+ EXPECT(build.includes(*dependency));
+ }
+ }
+}
+
+TEST_CASE(a_feature_the_build_lacks_is_never_enabled)
+{
+ FeatureOverrides overrides;
+ overrides.force_enabled.set(Feature::YCbCrImport);
+ auto decisions = PlatformFeatureDecisions::evaluate({}, overrides, {}, test_rules, Build {});
+ EXPECT_EQ(decisions.status_of(Feature::YCbCrImport).state, FeatureStatus::State::NotBuilt);
+ // Without Vulkan, nothing the probe reports says that the GPU cannot paint.
+ EXPECT_EQ(decisions.features_for(FeatureProcess::Compositor).to_byte_string(), "gpu_painting"sv);
+}
+
+TEST_CASE(a_matching_rule_blocklists_its_feature)
+{
+ auto decisions = evaluate(facts_with_a_gpu());
+ EXPECT(decisions.is_enabled(Feature::GpuPainting));
+
+ auto const& status = decisions.status_of(Feature::YCbCrImport);
+ EXPECT_EQ(status.state, FeatureStatus::State::Blocklisted);
+ EXPECT_EQ(status.rule_id, "test-nvidia-ycbcr"sv);
+
+ auto facts = facts_with_a_gpu();
+ facts.gpu->vendor_id = 0x1002;
+ EXPECT(evaluate(facts).is_enabled(Feature::YCbCrImport));
+}
+
+TEST_CASE(without_a_gpu_nothing_is_enabled)
+{
+ SystemFacts facts;
+ auto decisions = evaluate(facts);
+
+ EXPECT_EQ(decisions.status_of(Feature::GpuPainting).state, FeatureStatus::State::Unsupported);
+ auto const& status = decisions.status_of(Feature::YCbCrImport);
+ EXPECT_EQ(status.state, FeatureStatus::State::BlockedByDependency);
+ EXPECT_EQ(status.blocking_feature, Feature::GpuPainting);
+}
+
+TEST_CASE(a_failed_probe_turns_off_gpu_painting)
+{
+ SystemFacts facts;
+ facts.probe_failure = "The probe crashed"_string;
+ auto decisions = evaluate(facts);
+ auto const& status = decisions.status_of(Feature::GpuPainting);
+ EXPECT_EQ(status.state, FeatureStatus::State::Unsupported);
+ EXPECT(status.reason.contains("The probe crashed"sv));
+}
+
+TEST_CASE(a_missing_capability_is_unsupported_rather_than_blocklisted)
+{
+ auto facts = facts_with_a_gpu();
+ facts.gpu->supports_ycbcr_sampling = false;
+ EXPECT_EQ(evaluate(facts).status_of(Feature::YCbCrImport).state, FeatureStatus::State::Unsupported);
+}
+
+TEST_CASE(disabling_a_feature_turns_off_its_dependents_with_the_root_cause)
+{
+ FeatureOverrides overrides;
+ overrides.disabled.set(Feature::GpuPainting);
+ auto decisions = evaluate(facts_with_a_gpu(), overrides);
+
+ EXPECT_EQ(decisions.status_of(Feature::GpuPainting).state, FeatureStatus::State::DisabledByUser);
+ EXPECT_EQ(decisions.status_of(Feature::YCbCrImport).blocking_feature, Feature::GpuPainting);
+}
+
+TEST_CASE(force_enabling_overrides_rules_and_disables)
+{
+ FeatureOverrides overrides;
+ overrides.force_enabled.set(Feature::YCbCrImport);
+ overrides.disabled.set(Feature::YCbCrImport);
+ auto decisions = evaluate(facts_with_a_gpu(), overrides);
+
+ EXPECT(decisions.is_enabled(Feature::YCbCrImport));
+ EXPECT(decisions.status_of(Feature::YCbCrImport).forced);
+ EXPECT_EQ(decisions.status_of(Feature::YCbCrImport).rule_id, "test-nvidia-ycbcr"sv);
+
+ overrides.disabled.clear();
+ auto facts = facts_with_a_gpu();
+ facts.gpu->vendor_id = 0x1002;
+ decisions = evaluate(facts, overrides);
+ EXPECT(!decisions.status_of(Feature::YCbCrImport).forced);
+ EXPECT(decisions.status_of(Feature::YCbCrImport).reason.is_empty());
+}
+
+TEST_CASE(a_disabled_feature_still_names_the_rule_that_matched_it)
+{
+ FeatureOverrides overrides;
+ overrides.disabled.set(Feature::YCbCrImport);
+ auto decisions = evaluate(facts_with_a_gpu(), overrides);
+ auto const& status = decisions.status_of(Feature::YCbCrImport);
+ EXPECT_EQ(status.state, FeatureStatus::State::DisabledByUser);
+ EXPECT_EQ(status.rule_id, "test-nvidia-ycbcr"sv);
+}
+
+TEST_CASE(force_enabling_does_not_reach_past_a_dependency)
+{
+ FeatureOverrides overrides;
+ overrides.disabled.set(Feature::GpuPainting);
+ overrides.force_enabled.set(Feature::YCbCrImport);
+ auto decisions = evaluate(facts_with_a_gpu(), overrides);
+
+ EXPECT_EQ(decisions.status_of(Feature::YCbCrImport).state, FeatureStatus::State::BlockedByDependency);
+}
+
+TEST_CASE(force_enabling_cannot_supply_a_capability)
+{
+ auto facts = facts_with_a_gpu();
+ facts.gpu->supports_ycbcr_sampling = false;
+ FeatureOverrides overrides;
+ overrides.force_enabled.set(Feature::YCbCrImport);
+ EXPECT_EQ(evaluate(facts, overrides).status_of(Feature::YCbCrImport).state, FeatureStatus::State::Unsupported);
+}
+
+TEST_CASE(runtime_failures_win_over_force_enabling)
+{
+ FeatureOverrides overrides;
+ overrides.force_enabled.set(Feature::GpuPainting);
+ HashMap<Feature, String> runtime_failures;
+ runtime_failures.set(Feature::GpuPainting, "The Compositor crashed repeatedly"_string);
+ auto decisions = evaluate(facts_with_a_gpu(), overrides, runtime_failures);
+
+ EXPECT_EQ(decisions.status_of(Feature::GpuPainting).state, FeatureStatus::State::FailedAtRuntime);
+ EXPECT_EQ(decisions.status_of(Feature::YCbCrImport).blocking_feature, Feature::GpuPainting);
+}
+
+TEST_CASE(overrides_that_turn_everything_off_need_no_facts)
+{
+ EXPECT(!PlatformFeatureDecisions::decides_without_facts(FeatureProcess::Compositor, {}, Build::with_every_feature()));
+
+ FeatureOverrides overrides;
+ overrides.disabled.set(Feature::GpuPainting);
+ EXPECT(PlatformFeatureDecisions::decides_without_facts(FeatureProcess::Compositor, overrides, Build::with_every_feature()));
+
+ overrides.force_enabled.set(Feature::GpuPainting);
+ EXPECT(!PlatformFeatureDecisions::decides_without_facts(FeatureProcess::Compositor, overrides, Build::with_every_feature()));
+}
+
+TEST_CASE(each_process_is_given_its_enabled_features)
+{
+ auto facts = facts_with_a_gpu();
+ facts.gpu->vendor_id = 0x1002;
+ EXPECT_EQ(evaluate(facts).features_for(FeatureProcess::Compositor).to_byte_string(), "gpu_painting,ycbcr_import"sv);
+ EXPECT_EQ(evaluate(facts_with_a_gpu()).features_for(FeatureProcess::Compositor).to_byte_string(), "gpu_painting"sv);
+}
+
+TEST_CASE(process_features_round_trip_through_their_text_form)
+{
+ auto features = MUST(ProcessFeatures::from_string(FeatureProcess::Compositor, "ycbcr_import,gpu_painting"sv));
+ EXPECT(features.is_enabled(Feature::GpuPainting));
+ EXPECT(features.is_enabled(Feature::YCbCrImport));
+ EXPECT_EQ(features.to_byte_string(), "gpu_painting,ycbcr_import"sv);
+
+ auto none = MUST(ProcessFeatures::from_string(FeatureProcess::Compositor, ""sv));
+ EXPECT(!none.is_enabled(Feature::GpuPainting));
+}
+
+TEST_CASE(process_features_reject_unknown_features)
+{
+ EXPECT(ProcessFeatures::from_string(FeatureProcess::Compositor, "gpu_painting,teleportation"sv).is_error());
+}
+
+TEST_CASE(system_facts_round_trip_through_json)
+{
+ auto facts = facts_with_a_gpu();
+ EXPECT(MUST(SystemFacts::from_json(facts.to_json().serialized())) == facts);
+
+ facts.gpu.clear();
+ EXPECT(MUST(SystemFacts::from_json(facts.to_json().serialized())) == facts);
+}
+
+TEST_CASE(system_facts_reject_malformed_json)
+{
+ EXPECT(SystemFacts::from_json("[]"sv).is_error());
+ EXPECT(SystemFacts::from_json("{\"gpu\":3}"sv).is_error());
+
+ auto facts = facts_with_a_gpu();
+ auto json = facts.to_json();
+ json.get_object("gpu"sv)->remove("supports_ycbcr_sampling"sv);
+ EXPECT(SystemFacts::from_json(json.serialized()).is_error());
+
+ facts.gpu->driver_info = MUST(String::repeated('x', 1025));
+ EXPECT(SystemFacts::from_json(facts.to_json().serialized()).is_error());
+}