Skip to content

Truly independent web browser

LibCompositing+LibWeb: Remove the C++ WebGL command stream

Aliaksandr Kalenikc83639b40a3b
diff --git a/Libraries/LibCompositing/CMakeLists.txt b/Libraries/LibCompositing/CMakeLists.txt
index 84cdd79ce5a..fdbe0ea0fd5 100644
--- a/Libraries/LibCompositing/CMakeLists.txt
+++ b/Libraries/LibCompositing/CMakeLists.txt
@@ -1,5 +1,3 @@
-include(libcompositing_generators)
-
set(SOURCES
CanvasColorSpace.cpp
DisplayList/DisplayListResourceEncoding.cpp
@@ -12,12 +10,8 @@ set(SOURCES
UIOverlays.cpp
Video/VideoFrameHold.cpp
Video/VideoFramePresentationPage.cpp
- WebGL/TextureUpload.cpp
- WebGL/WebGLCommandList.cpp
)
-generate_compositing_webgl_implementation()
-
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Services/Compositor)
compile_ipc(${LADYBIRD_SOURCE_DIR}/Services/Compositor/CompositorControlClient.ipc ${CMAKE_BINARY_DIR}/Services/Compositor/CompositorControlClientEndpoint.h)
compile_ipc(${LADYBIRD_SOURCE_DIR}/Services/Compositor/CompositorControlServer.ipc ${CMAKE_BINARY_DIR}/Services/Compositor/CompositorControlServerEndpoint.h)
@@ -32,7 +26,6 @@ compile_ipc(FontClient.ipc FontClientEndpoint.h)
compile_ipc(FontServer.ipc FontServerEndpoint.h)
set(GENERATED_SOURCES
- WebGL/WebGLCommands.cpp
../../Services/Compositor/CompositorControlClientEndpoint.h
../../Services/Compositor/CompositorControlServerEndpoint.h
../../Services/Compositor/CompositorPresentationClientEndpoint.h
@@ -61,19 +54,6 @@ ladybird_lib(LibCompositing compositing EXPLICIT_SYMBOL_EXPORT)
target_link_libraries(LibCompositing PUBLIC LibWebCommon)
target_link_libraries(LibCompositing PRIVATE LibCore LibGfx LibIPC LibMedia LibThreading libcompositing_rust)
-# The generated WebGLCommands.h includes the generated GLFunctions.h.
-add_dependencies(LibCompositing generate_GLFunctions.cpp)
-
-# The WebGL command stream headers include ANGLE's GLES headers for the GL constants and types,
-# but the GL entry points live in the Compositor. Hand out only ANGLE's compile interface, to this
-# library and to whatever includes its headers, so nothing that links LibCompositing pulls ANGLE in.
-foreach(angle_target IN LISTS ANGLE_TARGETS)
- target_include_directories(LibCompositing PUBLIC $<TARGET_PROPERTY:${angle_target},INTERFACE_INCLUDE_DIRECTORIES>)
- target_include_directories(LibCompositing SYSTEM PUBLIC $<TARGET_PROPERTY:${angle_target},INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>)
- target_compile_definitions(LibCompositing PUBLIC $<TARGET_PROPERTY:${angle_target},INTERFACE_COMPILE_DEFINITIONS>)
- target_compile_options(LibCompositing PRIVATE $<TARGET_PROPERTY:${angle_target},INTERFACE_COMPILE_OPTIONS>)
-endforeach()
-
get_target_property(_libcompositing_rust_lib libcompositing_rust IMPORTED_LOCATION)
if ((LINUX OR BSD) AND NOT BUILD_SHARED_LIBS)
target_link_options(LibCompositing INTERFACE LINKER:--allow-multiple-definition)
diff --git a/Libraries/LibCompositing/Rust/generate/webgl_wire.rs b/Libraries/LibCompositing/Rust/generate/webgl_wire.rs
index dd7f1231c9a..7755a97f313 100644
--- a/Libraries/LibCompositing/Rust/generate/webgl_wire.rs
+++ b/Libraries/LibCompositing/Rust/generate/webgl_wire.rs
@@ -5,12 +5,11 @@
*/
//! Writes the vocabulary of the WebGL command stream: the command types, the synchronous call types and the struct of
-//! each, which src/webgl/vocabulary.rs includes. The C++ side of the stream gets the same from
-//! Meta/Generators/generate_libweb_webgl_commands.py.
+//! each, which src/webgl/vocabulary.rs includes.
use std::fmt::Write;
-use crate::webgl_wire_model::{Vocabulary, WireStruct, WireType, rust_identifier, wire_layout_name_hash};
+use crate::webgl_wire_model::{Vocabulary, WireStruct, WireType, rust_identifier};
/// A field of the Rust struct: one of the model, or the bytes that the C ABI leaves unused, which the struct spells
/// out so that all of its bytes are initialized and it can be written to the stream as bytes.
@@ -127,32 +126,8 @@ fn write_type_enum(out: &mut String, enum_name: &str, count_name: &str, descript
writeln!(out, "#[cfg(test)]\npub const {count_name}: u16 = {};\n", names.len()).unwrap();
}
-fn write_layout_words(out: &mut String, rust_path: &str, layout: &WireStruct) {
- writeln!(out, " // {}", layout.cpp_name).unwrap();
- writeln!(
- out,
- " {:#010x}, size_of::<{rust_path}>() as u32, align_of::<{rust_path}>() as u32, {},",
- wire_layout_name_hash(&layout.cpp_name),
- layout.fields.len()
- )
- .unwrap();
- for field in &layout.fields {
- writeln!(
- out,
- " {:#010x}, {:#010x}, offset_of!({rust_path}, {}) as u32, size_of::<{}>() as u32,",
- wire_layout_name_hash(&field.spec.name),
- wire_layout_name_hash(&field.spec.cpp_type),
- rust_identifier(&field.spec.name),
- field.wire_type.rust_type()
- )
- .unwrap();
- }
-}
-
pub fn write_wire_vocabulary(vocabulary: &Vocabulary) -> String {
let mut out = String::from("// Generated by build.rs from Libraries/LibCompositing/WebGL/GLFunctions.json.\n\n");
- out.push_str("use core::mem::offset_of;\n\n");
- out.push_str("use crate::webgl::wire::DataSpan;\n\n");
let command_names: Vec<&str> = vocabulary
.commands
@@ -163,7 +138,7 @@ pub fn write_wire_vocabulary(vocabulary: &Vocabulary) -> String {
&mut out,
"CommandType",
"COMMAND_TYPE_COUNT",
- "What a record of the command stream is, in the order of the C++ enum `WebGLCommandType`.",
+ "What a record of the command stream is.",
&command_names,
);
let sync_call_names: Vec<&str> = vocabulary
@@ -175,7 +150,7 @@ pub fn write_wire_vocabulary(vocabulary: &Vocabulary) -> String {
&mut out,
"SyncCallType",
"SYNC_CALL_TYPE_COUNT",
- "What a synchronous call is, in the order of the C++ enum `WebGLSyncCallType`.",
+ "What a synchronous call is.",
&sync_call_names,
);
let max_command_struct_size = vocabulary
@@ -191,9 +166,7 @@ pub fn write_wire_vocabulary(vocabulary: &Vocabulary) -> String {
)
.unwrap();
- out.push_str(
- "/// The structs of the records of the command stream, which are those of the C++ namespace `Commands`.\n",
- );
+ out.push_str("/// The structs of the records of the command stream.\n");
out.push_str("pub mod commands {\n");
out.push_str(" use core::mem::offset_of;\n\n");
out.push_str(" use super::CommandType;\n");
@@ -207,7 +180,7 @@ pub fn write_wire_vocabulary(vocabulary: &Vocabulary) -> String {
}
out.push_str("}\n\n");
- out.push_str("/// The structs of the synchronous calls, which are those of the C++ namespace `SyncCalls`.\n");
+ out.push_str("/// The structs of the synchronous calls.\n");
out.push_str("pub mod sync_calls {\n");
out.push_str(" use core::mem::offset_of;\n\n");
out.push_str(" use super::SyncCallType;\n");
@@ -226,25 +199,5 @@ pub fn write_wire_vocabulary(vocabulary: &Vocabulary) -> String {
}
out.push_str("}\n\n");
- out.push_str(
- "/// The layout of every struct above as this compiler laid it out, in the form of the table that the C++ side\n\
- /// reports: per struct the hash of its C++ name, its size, its alignment and the number of its fields, then\n\
- /// per field the hash of its name, the hash of the name of its C++ type, its offset and its size.\n",
- );
- out.push_str("#[allow(clippy::unreadable_literal, reason = \"the hashes are not read\")]\n");
- out.push_str("pub static WIRE_STRUCT_LAYOUTS: &[u32] = &[\n");
- for entry in &vocabulary.commands {
- write_layout_words(
- &mut out,
- &format!("commands::{}", entry.function.command_name()),
- &entry.layout,
- );
- }
- for entry in &vocabulary.sync_calls {
- let name = entry.function.command_name();
- write_layout_words(&mut out, &format!("sync_calls::{name}Request"), &entry.request);
- write_layout_words(&mut out, &format!("sync_calls::{name}Reply"), &entry.reply);
- }
- out.push_str("];\n");
out
}
diff --git a/Libraries/LibCompositing/Rust/generate/webgl_wire_model.rs b/Libraries/LibCompositing/Rust/generate/webgl_wire_model.rs
index 3db9582af7f..57d4d6250c2 100644
--- a/Libraries/LibCompositing/Rust/generate/webgl_wire_model.rs
+++ b/Libraries/LibCompositing/Rust/generate/webgl_wire_model.rs
@@ -5,10 +5,7 @@
*/
//! The model of Libraries/LibCompositing/WebGL/GLFunctions.json: which entries the command stream carries and which
-//! structs they serialize to. It mirrors Meta/Generators/libweb_webgl.py, which the C++ side of the stream is
-//! generated from, so the two have to change together. What keeps them from drifting apart silently: the model
-//! rejects everything in the JSON that it does not know, and the recorder compares the layout of its structs with
-//! the one that the C++ side reports before it records anything.
+//! structs they serialize to. The model rejects everything in the JSON that it does not know.
use serde_json::{Map, Value};
@@ -565,7 +562,7 @@ pub struct WireField {
#[derive(Debug)]
pub struct WireStruct {
- /// The name of the struct inside the C++ namespace Compositing::WebGL, which the table of layout words hashes.
+ /// The name of the struct, such as `Commands::BufferData`.
pub cpp_name: String,
pub fields: Vec<WireField>,
pub size: usize,
@@ -659,10 +656,3 @@ pub fn vocabulary(functions: &[Function]) -> Result<Vocabulary<'_>, String> {
}
Ok(Vocabulary { commands, sync_calls })
}
-
-/// The 32-bit FNV-1a hash that stands for the name of a struct, a field or a type in the table of layout words.
-pub fn wire_layout_name_hash(name: &str) -> u32 {
- name.bytes().fold(0x811C_9DC5, |hash, byte| {
- (hash ^ u32::from(byte)).wrapping_mul(0x0100_0193)
- })
-}
diff --git a/Libraries/LibCompositing/Rust/generate/webgl_wire_model_tests.rs b/Libraries/LibCompositing/Rust/generate/webgl_wire_model_tests.rs
index 3527f86dacc..e3635ee386b 100644
--- a/Libraries/LibCompositing/Rust/generate/webgl_wire_model_tests.rs
+++ b/Libraries/LibCompositing/Rust/generate/webgl_wire_model_tests.rs
@@ -156,13 +156,6 @@ fn what_the_model_does_not_know_is_rejected() {
);
}
-#[test]
-fn a_name_hash_is_fnv_1a() {
- assert_eq!(wire_layout_name_hash(""), 0x811C_9DC5);
- assert_eq!(wire_layout_name_hash("a"), 0xE40C_292C);
- assert_eq!(wire_layout_name_hash("Commands::ActiveTexture"), 0x9B0F_0F7C);
-}
-
#[test]
fn what_the_replayer_needs_is_read_from_the_json() {
let functions = parse_functions(
diff --git a/Libraries/LibCompositing/Rust/src/webgl/vocabulary.rs b/Libraries/LibCompositing/Rust/src/webgl/vocabulary.rs
index 6f2b7537091..6d5af9b9750 100644
--- a/Libraries/LibCompositing/Rust/src/webgl/vocabulary.rs
+++ b/Libraries/LibCompositing/Rust/src/webgl/vocabulary.rs
@@ -65,26 +65,4 @@ mod tests {
assert!((CommandType::Viewport as u16) < COMMAND_TYPE_COUNT);
assert!((SyncCallType::GetError as u16) < SYNC_CALL_TYPE_COUNT);
}
-
- #[test]
- fn the_table_of_layout_words_describes_every_struct() {
- let mut struct_count = 0;
- let mut words = WIRE_STRUCT_LAYOUTS;
- while let [_name_hash, size, alignment, field_count, rest @ ..] = words {
- assert!(*size >= 1 && size % alignment == 0);
- let mut end_of_previous_field = 0;
- let (fields, rest) = rest.split_at(*field_count as usize * 4);
- for [_name_hash, _type_hash, offset, field_size] in fields.as_chunks::<4>().0 {
- assert!(*offset >= end_of_previous_field && offset + field_size <= *size);
- end_of_previous_field = offset + field_size;
- }
- struct_count += 1;
- words = rest;
- }
- assert!(words.is_empty());
- assert_eq!(
- struct_count,
- usize::from(COMMAND_TYPE_COUNT) + 2 * usize::from(SYNC_CALL_TYPE_COUNT)
- );
- }
}
diff --git a/Libraries/LibCompositing/Rust/src/webgl/wire.rs b/Libraries/LibCompositing/Rust/src/webgl/wire.rs
index 5b1c353adc9..16d8ec3ed24 100644
--- a/Libraries/LibCompositing/Rust/src/webgl/wire.rs
+++ b/Libraries/LibCompositing/Rust/src/webgl/wire.rs
@@ -5,8 +5,7 @@
*/
//! The framing of the WebGL command stream: how a struct and the data that belongs to it become the bytes of a record
-//! or of a synchronous call. Libraries/LibCompositing/WebGL/WebGLCommandList.{h,cpp} is the C++ side of the same
-//! format, which reads what this writes.
+//! or of a synchronous call, and back.
use core::mem::size_of;
use core::ptr;
diff --git a/Libraries/LibCompositing/WebGL/TextureUpload.cpp b/Libraries/LibCompositing/WebGL/TextureUpload.cpp
deleted file mode 100644
index 4e570081e75..00000000000
--- a/Libraries/LibCompositing/WebGL/TextureUpload.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2026, Aliaksandr Kalenik <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <GLES3/gl3.h>
-
-#include <AK/Debug.h>
-#include <LibCompositing/WebGL/TextureUpload.h>
-
-namespace Compositing::WebGL {
-
-Optional<Gfx::ExportFormat> texture_export_format(GLenum format, GLenum type)
-{
- switch (format) {
- case GL_RGB:
- switch (type) {
- case GL_UNSIGNED_BYTE:
- return Gfx::ExportFormat::RGB888;
- case GL_UNSIGNED_SHORT_5_6_5:
- return Gfx::ExportFormat::RGB565;
- default:
- break;
- }
- break;
- case GL_RGBA:
- switch (type) {
- case GL_UNSIGNED_BYTE:
- return Gfx::ExportFormat::RGBA8888;
- case GL_UNSIGNED_SHORT_4_4_4_4:
- // FIXME: This is not exactly the same as RGBA.
- return Gfx::ExportFormat::RGBA4444;
- case GL_UNSIGNED_SHORT_5_5_5_1:
- return Gfx::ExportFormat::RGBA5551;
- default:
- break;
- }
- break;
- case GL_ALPHA:
- switch (type) {
- case GL_UNSIGNED_BYTE:
- return Gfx::ExportFormat::Alpha8;
- default:
- break;
- }
- break;
- case GL_LUMINANCE:
- switch (type) {
- case GL_UNSIGNED_BYTE:
- return Gfx::ExportFormat::Luminance8;
- default:
- break;
- }
- break;
- case GL_LUMINANCE_ALPHA:
- switch (type) {
- case GL_UNSIGNED_BYTE:
- return Gfx::ExportFormat::LuminanceAlpha88;
- default:
- break;
- }
- break;
- default:
- break;
- }
-
- dbgln("WebGL: Unsupported format and type combination. format: 0x{:04x}, type: 0x{:04x}", format, type);
- return {};
-}
-
-}
diff --git a/Libraries/LibCompositing/WebGL/TextureUpload.h b/Libraries/LibCompositing/WebGL/TextureUpload.h
deleted file mode 100644
index 00f40ed2ba0..00000000000
--- a/Libraries/LibCompositing/WebGL/TextureUpload.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright (c) 2026, Aliaksandr Kalenik <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/Optional.h>
-#include <LibCompositing/Export.h>
-#include <LibCompositing/WebGL/Types.h>
-#include <LibGfx/ExportFormat.h>
-
-namespace Compositing::WebGL {
-
-COMPOSITING_API Optional<Gfx::ExportFormat> texture_export_format(GLenum format, GLenum type);
-
-}
diff --git a/Libraries/LibCompositing/WebGL/Types.h b/Libraries/LibCompositing/WebGL/Types.h
index 8a676696aa2..4af98c271c0 100644
--- a/Libraries/LibCompositing/WebGL/Types.h
+++ b/Libraries/LibCompositing/WebGL/Types.h
@@ -6,40 +6,11 @@
#pragma once
-#include <AK/Types.h>
-#include <LibCompositing/Forward.h>
-
namespace Compositing::WebGL {
-using GLenum = unsigned int;
-using GLuint = unsigned int;
-using GLint = int;
-using GLsizei = int;
-using GLintptr = long long;
-using GLchar = char;
-
-// FIXME: This should really be "struct __GLsync*", but the linker doesn't recognise it.
-// Since this conflicts with the original definition of GLsync, the suffix "Internal" has been added.
-using GLsyncInternal = void*;
-
enum class WebGLVersion {
WebGL1,
WebGL2,
};
-static constexpr int max_webgl_drawing_buffer_dimension = 16384;
-
-using WebGLObjectId = u32;
-
-struct WebGLDataSpan {
- u32 offset { 0 };
- u32 size { 0 };
-};
-
-struct ReadPixelsResult {
- GLsizei length { 0 };
- GLsizei columns { 0 };
- GLsizei rows { 0 };
-};
-
}
diff --git a/Libraries/LibCompositing/WebGL/WebGLCommandList.cpp b/Libraries/LibCompositing/WebGL/WebGLCommandList.cpp
deleted file mode 100644
index 4c71f261212..00000000000
--- a/Libraries/LibCompositing/WebGL/WebGLCommandList.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2026, Aliaksandr Kalenik <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibCompositing/WebGL/WebGLCommandList.h>
-
-namespace Compositing::WebGL {
-
-static size_t payload_layout_size(ReadonlyBytes payload, ReadonlyBytes inline_data, ReadonlyBytes more_inline_data)
-{
- auto size = payload.size();
- if (!inline_data.is_empty())
- size = align_up_to(size, WebGLCommandList::command_alignment) + inline_data.size();
- if (!more_inline_data.is_empty())
- size = align_up_to(size, WebGLCommandList::command_alignment) + more_inline_data.size();
- return size;
-}
-
-static void write_payload(Bytes destination, ReadonlyBytes payload, ReadonlyBytes inline_data, ReadonlyBytes more_inline_data)
-{
- __builtin_memcpy(destination.data(), payload.data(), payload.size());
- auto cursor = payload.size();
- for (auto blob : { inline_data, more_inline_data }) {
- if (blob.is_empty())
- continue;
- auto offset = align_up_to(cursor, WebGLCommandList::command_alignment);
- __builtin_memset(destination.offset_pointer(cursor), 0, offset - cursor);
- __builtin_memcpy(destination.offset_pointer(offset), blob.data(), blob.size());
- cursor = offset + blob.size();
- }
- __builtin_memset(destination.offset_pointer(cursor), 0, destination.size() - cursor);
-}
-
-ByteBuffer WebGLSyncCall::encode_reply_bytes(ReadonlyBytes reply, ReadonlyBytes inline_data, ReadonlyBytes more_inline_data)
-{
- VERIFY(more_inline_data.is_empty() || !inline_data.is_empty());
-
- auto reply_size = align_up_to(payload_layout_size(reply, inline_data, more_inline_data), WebGLCommandList::command_alignment);
- auto bytes = MUST(ByteBuffer::create_uninitialized(reply_size));
- write_payload(bytes, reply, inline_data, more_inline_data);
- return bytes;
-}
-
-}
diff --git a/Libraries/LibCompositing/WebGL/WebGLCommandList.h b/Libraries/LibCompositing/WebGL/WebGLCommandList.h
deleted file mode 100644
index 0842aa00b21..00000000000
--- a/Libraries/LibCompositing/WebGL/WebGLCommandList.h
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (c) 2026, Aliaksandr Kalenik <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/Assertions.h>
-#include <AK/ByteBuffer.h>
-#include <AK/Error.h>
-#include <AK/Span.h>
-#include <AK/StdLibExtras.h>
-#include <LibCompositing/Export.h>
-#include <LibCompositing/WebGL/WebGLCommands.h>
-
-namespace Compositing::WebGL {
-
-struct WebGLCommandHeader {
- WebGLCommandType type;
- u32 payload_size { 0 }; // command struct + inline data + trailing padding
-};
-static_assert(IsTriviallyCopyable<WebGLCommandHeader>);
-
-class COMPOSITING_API WebGLCommandList {
-public:
- static constexpr size_t command_alignment = 16;
-
- static constexpr u32 first_inline_data_offset(size_t command_size)
- {
- return static_cast<u32>(align_up_to(command_size, command_alignment));
- }
-
- static constexpr u32 next_inline_data_offset(WebGLDataSpan previous)
- {
- return static_cast<u32>(align_up_to(previous.offset + previous.size, command_alignment));
- }
-
- template<typename Callback>
- static ErrorOr<void> for_each_command(ReadonlyBytes bytes, Callback&& callback)
- {
- size_t offset = 0;
- while (offset < bytes.size()) {
- if (bytes.size() - offset < sizeof(WebGLCommandHeader))
- return Error::from_string_literal("Truncated WebGL command header");
- WebGLCommandHeader header;
- __builtin_memcpy(&header, bytes.offset_pointer(offset), sizeof(header));
- if (to_underlying(header.type) >= webgl_command_type_count)
- return Error::from_string_literal("Invalid WebGL command type");
- if (header.payload_size > bytes.size() - offset - sizeof(header))
- return Error::from_string_literal("Truncated WebGL command payload");
- auto payload = bytes.slice(offset + sizeof(header), header.payload_size);
- TRY(visit_webgl_command_type(header.type, [&]<typename Command>() -> ErrorOr<void> {
- if (payload.size() < sizeof(Command))
- return Error::from_string_literal("WebGL command payload too small");
- Command command;
- __builtin_memcpy(&command, payload.data(), sizeof(Command));
- return callback(command, payload);
- }));
- offset += sizeof(WebGLCommandHeader) + header.payload_size;
- }
- return {};
- }
-
- static ReadonlyBytes resolve_data_span(ReadonlyBytes payload, WebGLDataSpan span)
- {
- VERIFY(span.offset <= payload.size());
- VERIFY(span.size <= payload.size() - span.offset);
- return payload.slice(span.offset, span.size);
- }
-
- template<typename T>
- static Span<T const> resolve_typed_span(ReadonlyBytes payload, WebGLDataSpan span)
- {
- auto bytes = resolve_data_span(payload, span);
- VERIFY(reinterpret_cast<uintptr_t>(bytes.data()) % alignof(T) == 0);
- VERIFY(bytes.size() % sizeof(T) == 0);
- return Span<T const> { reinterpret_cast<T const*>(bytes.data()), bytes.size() / sizeof(T) };
- }
-
- static ReadonlyBytes resolve_string_span(ReadonlyBytes payload, WebGLDataSpan span)
- {
- auto bytes = resolve_data_span(payload, span);
- VERIFY(!bytes.is_empty());
- VERIFY(bytes[bytes.size() - 1] == 0);
- return bytes;
- }
-};
-
-struct WebGLSyncCallHeader {
- WebGLSyncCallType type;
- u32 payload_size { 0 };
-};
-static_assert(IsTriviallyCopyable<WebGLSyncCallHeader>);
-
-class COMPOSITING_API WebGLSyncCall {
-public:
- template<typename Callback>
- static ErrorOr<ByteBuffer> dispatch_request(ReadonlyBytes bytes, Callback&& callback)
- {
- if (bytes.size() < sizeof(WebGLSyncCallHeader))
- return Error::from_string_literal("Truncated WebGL sync call header");
- WebGLSyncCallHeader header;
- __builtin_memcpy(&header, bytes.data(), sizeof(header));
- if (to_underlying(header.type) >= webgl_sync_call_type_count)
- return Error::from_string_literal("Invalid WebGL sync call type");
- if (header.payload_size != bytes.size() - sizeof(header))
- return Error::from_string_literal("Truncated WebGL sync call payload");
- auto payload = bytes.slice(sizeof(header), header.payload_size);
- return visit_webgl_sync_call_type(header.type, [&]<typename Call>() -> ErrorOr<ByteBuffer> {
- if (payload.size() < sizeof(typename Call::Request))
- return Error::from_string_literal("WebGL sync call payload too small");
- typename Call::Request request;
- __builtin_memcpy(&request, payload.data(), sizeof(request));
- return callback.template operator()<Call>(request, payload);
- });
- }
-
- template<typename Reply>
- static ByteBuffer encode_reply(Reply const& reply, ReadonlyBytes inline_data = {}, ReadonlyBytes more_inline_data = {})
- {
- return encode_reply_bytes({ &reply, sizeof(reply) }, inline_data, more_inline_data);
- }
-
-private:
- static ByteBuffer encode_reply_bytes(ReadonlyBytes reply, ReadonlyBytes inline_data, ReadonlyBytes more_inline_data);
-};
-
-}
diff --git a/Libraries/LibCompositing/WebGL/WebGLSharedCommandBuffer.h b/Libraries/LibCompositing/WebGL/WebGLSharedCommandBuffer.h
deleted file mode 100644
index bd2986fbbfa..00000000000
--- a/Libraries/LibCompositing/WebGL/WebGLSharedCommandBuffer.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2026, Aliaksandr Kalenik <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/Atomic.h>
-#include <AK/Optional.h>
-#include <LibCore/AnonymousBuffer.h>
-
-namespace Compositing::WebGL {
-
-// WebContent records commands into the data region and publishes ranges via async IPC;
-// the Compositor stores each executed range's flush sequence number into the header.
-// The write cursor may rewind to the start only once that counter covers everything
-// published, so published bytes are never overwritten while still being read.
-class WebGLSharedCommandBuffer {
-public:
- static constexpr size_t data_region_offset = 128;
- static constexpr size_t default_data_region_capacity = 32 * MiB;
-
- WebGLSharedCommandBuffer() = default;
-
- static Optional<WebGLSharedCommandBuffer> adopt_received_buffer(Core::AnonymousBuffer buffer)
- {
- if (!buffer.is_valid() || buffer.size() <= data_region_offset)
- return {};
- return WebGLSharedCommandBuffer { move(buffer) };
- }
-
- bool is_valid() const { return m_buffer.is_valid(); }
-
- void store_executed_flush_sequence_number(u64 flush_sequence_number)
- {
- reinterpret_cast<Atomic<u64>*>(m_buffer.data<u8>())->store(flush_sequence_number, AK::MemoryOrder::memory_order_release);
- }
-
- ReadonlyBytes data_region() const
- {
- return { m_buffer.data<u8>() + data_region_offset, m_buffer.size() - data_region_offset };
- }
-
-private:
- explicit WebGLSharedCommandBuffer(Core::AnonymousBuffer buffer)
- : m_buffer(move(buffer))
- {
- }
-
- Core::AnonymousBuffer m_buffer;
-};
-
-}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs
index 229138c5e9e..aea109d1e28 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs
@@ -17,7 +17,6 @@ use super::canvas::Canvas;
use super::context_loss::{
fire_webgl_context_event, lose_contexts_of_this_thread, register_context, restore_contexts_of_this_thread,
};
-use super::fingerprint::verify_that_rust_and_cpp_agree_on_layouts_and_constants;
use super::host::{ContextCreation, RemoteContext};
use super::proxy::recorder::Proxy;
use super::state::{
@@ -151,7 +150,6 @@ pub unsafe extern "C" fn web_webgl_context_create(
) -> *mut c_void {
// SAFETY: The caller passes the live VM and a live realm.
let (vm, realm) = unsafe { realm_arguments(vm, arguments.realm) };
- verify_that_rust_and_cpp_agree_on_layouts_and_constants();
let canvas = Canvas {
cell: NonNull::new(arguments.canvas).expect("C++ passes the canvas"),
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/fingerprint.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/fingerprint.rs
deleted file mode 100644
index 87999f3554a..00000000000
--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/fingerprint.rs
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-//! The check that Rust and C++ agree on what each of them states for itself. The recorder and the replayer get their
-//! structs from GLFunctions.json, but through two generators, and the framing of the command stream, the capacity of
-//! its shared data region and the largest drawing buffer are constants on each side. A difference would not fail a
-//! build, and would make the replayer read garbage or the context report a drawing buffer that the compositor does not
-//! allocate, so the two sides are compared before the first context records.
-
-use std::sync::Once;
-
-use libcompositing_rust::webgl::vocabulary::WIRE_STRUCT_LAYOUTS;
-use libcompositing_rust::webgl::wire::{HEADER_PAYLOAD_SIZE_OFFSET, HEADER_SIZE, RECORD_ALIGNMENT};
-use libcompositing_rust::webgl::{DEFAULT_SHARED_DATA_REGION_CAPACITY, SHARED_DATA_REGION_OFFSET};
-
-use super::state::MAX_WEBGL_DRAWING_BUFFER_DIMENSION;
-
-/// RemoteWebGLTransportFFI.cpp has a struct of the same name, and reports the constants of the C++ side as one.
-#[derive(Debug, Default, PartialEq, Eq)]
-#[repr(C)]
-struct ConstantsRestatedInRust {
- record_alignment: usize,
- header_size: usize,
- header_payload_size_offset: usize,
- shared_data_region_offset: usize,
- shared_data_region_capacity: usize,
- max_drawing_buffer_dimension: usize,
-}
-
-unsafe extern "C" {
- fn compositing_webgl_wire_struct_layouts(out_word_count: *mut usize) -> *const u32;
- safe fn web_webgl_constants_restated_in_rust(out_constants: &mut ConstantsRestatedInRust);
-}
-
-pub(crate) fn verify_that_rust_and_cpp_agree_on_layouts_and_constants() {
- static VERIFIED: Once = Once::new();
- VERIFIED.call_once(|| {
- let mut constants_of_the_cpp_side = ConstantsRestatedInRust::default();
- web_webgl_constants_restated_in_rust(&mut constants_of_the_cpp_side);
- let constants_of_the_rust_side = ConstantsRestatedInRust {
- record_alignment: RECORD_ALIGNMENT,
- header_size: HEADER_SIZE,
- header_payload_size_offset: HEADER_PAYLOAD_SIZE_OFFSET,
- shared_data_region_offset: SHARED_DATA_REGION_OFFSET,
- shared_data_region_capacity: DEFAULT_SHARED_DATA_REGION_CAPACITY,
- max_drawing_buffer_dimension: usize::try_from(MAX_WEBGL_DRAWING_BUFFER_DIMENSION)
- .expect("the largest dimension of a drawing buffer is positive"),
- };
- assert!(
- constants_of_the_cpp_side == constants_of_the_rust_side,
- "the WebGL implementation restates constants of the C++ side ({constants_of_the_cpp_side:?}) differently \
- in Rust ({constants_of_the_rust_side:?})"
- );
-
- let mut word_count = 0;
- // SAFETY: The function returns a table that lives as long as the process, and stores its length.
- let replayer_layouts = unsafe {
- let words = compositing_webgl_wire_struct_layouts(&raw mut word_count);
- ak::slice_from_raw_parts(words, word_count)
- };
- let first_difference = replayer_layouts
- .iter()
- .zip(WIRE_STRUCT_LAYOUTS)
- .position(|(theirs, ours)| theirs != ours);
- assert!(
- first_difference.is_none() && replayer_layouts.len() == WIRE_STRUCT_LAYOUTS.len(),
- "the structs of the WebGL command stream differ between its recorder and its replayer, from word \
- {first_difference:?} of {} and {} layout words on; Libraries/LibCompositing/Rust/generate and \
- Meta/Generators/libweb_webgl.py have to derive the same structs from GLFunctions.json",
- WIRE_STRUCT_LAYOUTS.len(),
- replayer_layouts.len()
- );
- });
-}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/mod.rs
index 8afb6968e0f..7ac85451988 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/mod.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/mod.rs
@@ -27,8 +27,6 @@ pub(crate) mod exports;
#[cfg(not(test))]
pub(crate) mod extensions;
#[cfg(not(test))]
-pub(crate) mod fingerprint;
-#[cfg(not(test))]
pub(crate) mod gl_string;
#[cfg(not(test))]
pub(crate) mod host;
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index 607fa9cfc12..fdbd2110c5e 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -902,7 +902,6 @@ set(SOURCES
WebDriver/JSON.cpp
WebDriver/Screenshot.cpp
WebDriver/UserPrompt.cpp
- WebGL/RemoteWebGLTransportFFI.cpp
WebGL/WebGLRenderingContextBase.cpp
WebIDL/AbstractOperations.cpp
WebIDL/AsyncIterator.cpp
@@ -998,17 +997,6 @@ target_link_libraries(LibWeb PUBLIC LibCompositing LibWebCommon LibJSHeaders)
target_link_libraries(LibWeb PRIVATE LibCore LibCrypto LibHTTP LibGfx LibIPC LibRegex LibSyntax LibTextCodec LibUnicode LibAudio LibMedia LibMediaClient LibXML LibURL LibTLS LibRequests LibGC LibImageDecoderClient LibThreading LibWebRTCClient)
-# LibWeb still includes ANGLE's GLES headers for WebGL constants and types, but
-# the actual GL entry points live in the Compositor. Copy only ANGLE's compile
-# interface here so LibWeb can include those headers without linking ANGLE into
-# WebContent.
-foreach(angle_target IN LISTS ANGLE_TARGETS)
- target_include_directories(LibWeb PRIVATE $<TARGET_PROPERTY:${angle_target},INTERFACE_INCLUDE_DIRECTORIES>)
- target_include_directories(LibWeb SYSTEM PRIVATE $<TARGET_PROPERTY:${angle_target},INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>)
- target_compile_definitions(LibWeb PRIVATE $<TARGET_PROPERTY:${angle_target},INTERFACE_COMPILE_DEFINITIONS>)
- target_compile_options(LibWeb PRIVATE $<TARGET_PROPERTY:${angle_target},INTERFACE_COMPILE_OPTIONS>)
-endforeach()
-
# The library's Rust code: the bindings crate, which depends on the LibJS runtime and on libweb_rust, so that one archive
# holds all three and the runtime is in the process once. The runtime's features are LibJS's.
import_rust_crate(
diff --git a/Libraries/LibWeb/WebGL/RemoteWebGLTransportFFI.cpp b/Libraries/LibWeb/WebGL/RemoteWebGLTransportFFI.cpp
deleted file mode 100644
index 2145c9083c2..00000000000
--- a/Libraries/LibWeb/WebGL/RemoteWebGLTransportFFI.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibCompositing/WebGL/Types.h>
-#include <LibCompositing/WebGL/WebGLCommandList.h>
-#include <LibCompositing/WebGL/WebGLSharedCommandBuffer.h>
-#include <LibWeb/Loader/ResourceLoader.h>
-
-// What the WebGL implementation in Libraries/LibWeb/Bindings/Rust/src/web_gl asks of the rest of LibWeb besides its
-// canvas.
-
-namespace Web::WebGL {
-
-// What the WebGL implementation in Rust states for itself besides the command structs: the framing and the shared
-// data region that the recorder and the replayer of the command stream have to agree on, and the largest drawing
-// buffer that the compositor allocates. Rust compares its own constants with these before the first context records
-// (fingerprint.rs).
-struct ConstantsRestatedInRust {
- size_t record_alignment { 0 };
- size_t header_size { 0 };
- size_t header_payload_size_offset { 0 };
- size_t shared_data_region_offset { 0 };
- size_t shared_data_region_capacity { 0 };
- size_t max_drawing_buffer_dimension { 0 };
-};
-
-// NB: The recorder writes the header of a command and that of a synchronous call the same way.
-static_assert(sizeof(Compositing::WebGL::WebGLSyncCallHeader) == sizeof(Compositing::WebGL::WebGLCommandHeader));
-static_assert(offsetof(Compositing::WebGL::WebGLSyncCallHeader, payload_size) == offsetof(Compositing::WebGL::WebGLCommandHeader, payload_size));
-static_assert(offsetof(Compositing::WebGL::WebGLSyncCallHeader, type) == 0 && offsetof(Compositing::WebGL::WebGLCommandHeader, type) == 0);
-static_assert(sizeof(Compositing::WebGL::WebGLSyncCallType) == sizeof(u16) && sizeof(Compositing::WebGL::WebGLCommandType) == sizeof(u16));
-static_assert(sizeof(Compositing::WebGL::WebGLCommandHeader::payload_size) == sizeof(u32));
-
-// NB: `DataSpan` of libcompositing_rust::webgl::wire is two `u32`s in this order.
-static_assert(sizeof(Compositing::WebGL::WebGLDataSpan) == 2 * sizeof(u32));
-static_assert(offsetof(Compositing::WebGL::WebGLDataSpan, offset) == 0);
-static_assert(offsetof(Compositing::WebGL::WebGLDataSpan, size) == sizeof(u32));
-
-extern "C" {
-
-u8 web_navigator_compatibility_mode();
-void web_webgl_constants_restated_in_rust(ConstantsRestatedInRust* out_constants);
-}
-
-// The navigator compatibility mode, numbered as Web::NavigatorCompatibilityMode is: Chrome, Gecko, WebKit.
-u8 web_navigator_compatibility_mode()
-{
- return to_underlying(Web::ResourceLoader::navigator_compatibility_mode());
-}
-
-void web_webgl_constants_restated_in_rust(ConstantsRestatedInRust* out_constants)
-{
- *out_constants = {
- .record_alignment = Compositing::WebGL::WebGLCommandList::command_alignment,
- .header_size = sizeof(Compositing::WebGL::WebGLCommandHeader),
- .header_payload_size_offset = offsetof(Compositing::WebGL::WebGLCommandHeader, payload_size),
- .shared_data_region_offset = Compositing::WebGL::WebGLSharedCommandBuffer::data_region_offset,
- .shared_data_region_capacity = Compositing::WebGL::WebGLSharedCommandBuffer::default_data_region_capacity,
- .max_drawing_buffer_dimension = Compositing::WebGL::max_webgl_drawing_buffer_dimension,
- };
-}
-
-}
diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.cpp b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.cpp
index d3e797e734d..2ace23e5245 100644
--- a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.cpp
+++ b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.cpp
@@ -21,6 +21,7 @@
#include <LibWeb/HTML/HTMLImageElement.h>
#include <LibWeb/HTML/OffscreenCanvas.h>
#include <LibWeb/HTML/WindowOrWorkerGlobalScope.h>
+#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/WebGL/WebGL2RenderingContext.h>
#include <LibWeb/WebGL/WebGLRenderingContext.h>
@@ -70,6 +71,7 @@ void* web_webgl_canvas_wrapper(void* canvas, bool canvas_is_offscreen, void* rea
void* web_webgl_canvas_relevant_realm(void* canvas_host);
bool web_webgl_expose_experimental_interfaces();
Gfx::DecodedImageFrame* web_webgl_texture_image_frame(void* source_wrapper, TexImageSourceKind);
+u8 web_navigator_compatibility_mode();
}
static void* cell_of(WebGLRenderingContextBase const& context)
@@ -218,4 +220,10 @@ Gfx::DecodedImageFrame* web_webgl_texture_image_frame(void* source_wrapper, TexI
return new Gfx::DecodedImageFrame { frame.release_value() };
}
+// The navigator compatibility mode, numbered as Web::NavigatorCompatibilityMode is: Chrome, Gecko, WebKit.
+u8 web_navigator_compatibility_mode()
+{
+ return to_underlying(ResourceLoader::navigator_compatibility_mode());
+}
+
}
diff --git a/Meta/CMake/libcompositing_generators.cmake b/Meta/CMake/libcompositing_generators.cmake
deleted file mode 100644
index 54f87f50da0..00000000000
--- a/Meta/CMake/libcompositing_generators.cmake
+++ /dev/null
@@ -1,32 +0,0 @@
-function (generate_compositing_webgl_implementation)
- set(LIBCOMPOSITING_INPUT_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}")
-
- invoke_py_generator(
- "GLFunctions.cpp"
- "generate_libweb_webgl_functions.py"
- "${LIBCOMPOSITING_INPUT_FOLDER}/WebGL/GLFunctions.json"
- "WebGL/GLFunctions.h"
- "WebGL/GLFunctions.cpp"
- arguments -j "${LIBCOMPOSITING_INPUT_FOLDER}/WebGL/GLFunctions.json"
- dependencies "${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_webgl.py"
- )
-
- invoke_py_generator(
- "WebGLCommands.cpp"
- "generate_libweb_webgl_commands.py"
- "${LIBCOMPOSITING_INPUT_FOLDER}/WebGL/GLFunctions.json"
- "WebGL/WebGLCommands.h"
- "WebGL/WebGLCommands.cpp"
- arguments -j "${LIBCOMPOSITING_INPUT_FOLDER}/WebGL/GLFunctions.json"
- dependencies "${LADYBIRD_SOURCE_DIR}/Meta/Generators/libweb_webgl.py"
- )
-
- set(WEBGL_GENERATED_HEADERS
- "WebGL/GLFunctions.h"
- "WebGL/WebGLCommands.h"
- )
- list(TRANSFORM WEBGL_GENERATED_HEADERS PREPEND "${CMAKE_CURRENT_BINARY_DIR}/")
- if (ENABLE_INSTALL_HEADERS)
- install(FILES ${WEBGL_GENERATED_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/LibCompositing/WebGL")
- endif()
-endfunction()
diff --git a/Meta/Generators/generate_libweb_webgl_commands.py b/Meta/Generators/generate_libweb_webgl_commands.py
deleted file mode 100644
index b6ad56c4684..00000000000
--- a/Meta/Generators/generate_libweb_webgl_commands.py
+++ /dev/null
@@ -1,210 +0,0 @@
-#!/usr/bin/env python3
-
-# Copyright (c) 2026, Aliaksandr Kalenik <[email protected]>
-#
-# SPDX-License-Identifier: BSD-2-Clause
-
-import sys
-
-from pathlib import Path
-from typing import TextIO
-
-sys.path.append(str(Path(__file__).resolve().parent))
-
-from libweb_webgl import command_name
-from libweb_webgl import command_stream_entries
-from libweb_webgl import command_wire_fields
-from libweb_webgl import run_generator
-from libweb_webgl import sync_call_entries
-from libweb_webgl import sync_reply_wire_fields
-from libweb_webgl import sync_request_wire_fields
-from libweb_webgl import wire_layout_name_hash
-from libweb_webgl import wire_structs
-
-# Generates the WebGL command stream vocabulary from GLFunctions.json: one opcode and one
-# trivially-copyable struct per "command"/"gen" entry. The recorder (WebContent) and the
-# replayer (Compositor) are generated from the same source of truth, so the wire format
-# cannot drift between the two sides.
-
-# The command and sync-call vocabularies share their X-macro shape; everything but the
-# structs themselves is emitted by the helpers below.
-
-
-def write_type_enum(out: TextIO, macro: str, enum_name: str, count_name: str, names: list) -> None:
- out.write(f"#define {macro}(V) \\\n")
- for name in names:
- out.write(f" V({name}) \\\n")
- out.write(f"""
-enum class {enum_name} : u16 {{
-#define __ENUMERATE(name) name,
- {macro}(__ENUMERATE)
-#undef __ENUMERATE
-}};
-
-inline constexpr u16 {count_name} = {len(names)};
-""")
-
-
-def write_visit_function(out: TextIO, macro: str, enum_name: str, function_name: str, namespace: str) -> None:
- out.write(f"""
-template<typename Callback>
-decltype(auto) {function_name}({enum_name} type, Callback&& callback)
-{{
- switch (type) {{
-#define __ENUMERATE(name) \\
- case {enum_name}::name: \\
- return callback.template operator()<{namespace}::name>();
- {macro}(__ENUMERATE)
-#undef __ENUMERATE
- }}
- VERIFY_NOT_REACHED();
-}}
-""")
-
-
-def write_static_asserts(out: TextIO, macro: str, assert_body: str) -> None:
- out.write(f"""
-#define __ENUMERATE(name) {assert_body}
-{macro}(__ENUMERATE)
-#undef __ENUMERATE
-""")
-
-
-def write_header_file(out: TextIO, functions: list) -> None:
- commands = command_stream_entries(functions)
- sync_calls = sync_call_entries(functions)
-
- out.write("""#pragma once
-
-#include <AK/Assertions.h>
-#include <AK/Span.h>
-#include <AK/StdLibExtras.h>
-#include <AK/Types.h>
-#include <LibCompositing/Export.h>
-#include <LibCompositing/WebGL/GLFunctions.h>
-
-namespace Compositing::WebGL {
-
-""")
- write_type_enum(
- out,
- "ENUMERATE_WEBGL_COMMANDS",
- "WebGLCommandType",
- "webgl_command_type_count",
- [command_name(f) for f in commands],
- )
- out.write("\nnamespace Commands {\n")
- for f in commands:
- name = command_name(f)
- out.write(f"\nstruct {name} {{\n")
- for cpp_type, field_name in command_wire_fields(f):
- out.write(f" {cpp_type} {field_name} {{}};\n")
- out.write("};\n")
- out.write("\n}\n")
- write_visit_function(out, "ENUMERATE_WEBGL_COMMANDS", "WebGLCommandType", "visit_webgl_command_type", "Commands")
- write_static_asserts(out, "ENUMERATE_WEBGL_COMMANDS", "static_assert(IsTriviallyCopyable<Commands::name>);")
-
- out.write("\n")
- write_type_enum(
- out,
- "ENUMERATE_WEBGL_SYNC_CALLS",
- "WebGLSyncCallType",
- "webgl_sync_call_type_count",
- [command_name(f) for f in sync_calls],
- )
- out.write("\nnamespace SyncCalls {\n")
- for f in sync_calls:
- name = command_name(f)
- out.write(f"\nstruct {name} {{\n")
- out.write(" struct Request {\n")
- for cpp_type, field_name in sync_request_wire_fields(f):
- out.write(f" {cpp_type} {field_name} {{}};\n")
- out.write(" };\n")
- out.write(" struct Reply {\n")
- for cpp_type, field_name in sync_reply_wire_fields(f):
- out.write(f" {cpp_type} {field_name} {{}};\n")
- out.write(" };\n")
- out.write("};\n")
- out.write("\n}\n")
- write_visit_function(
- out, "ENUMERATE_WEBGL_SYNC_CALLS", "WebGLSyncCallType", "visit_webgl_sync_call_type", "SyncCalls"
- )
- write_static_asserts(
- out,
- "ENUMERATE_WEBGL_SYNC_CALLS",
- "static_assert(IsTriviallyCopyable<SyncCalls::name::Request>); static_assert(IsTriviallyCopyable<SyncCalls::name::Reply>);",
- )
- out.write("""
-// The layout of every struct that crosses the command stream, as the compiler of this side laid it out, for a recorder
-// that is not compiled from this header to compare its own against. A struct is the words (hash of its name, size,
-// alignment, number of fields) followed by the words (hash of its name, hash of the name of its type, offset, size)
-// of each of its fields.
-COMPOSITING_API ReadonlySpan<u32> webgl_wire_struct_layouts();
-
-}
-
-extern "C" COMPOSITING_API u32 const* compositing_webgl_wire_struct_layouts(size_t* out_word_count);
-""")
-
-
-def write_wire_struct_layout_assertions(out: TextIO, functions: list) -> None:
- out.write("""
-// The recorder and the replayer exchange these structs as bytes, and they can be compiled by different compilers, or
-// from definitions in different languages. So the layout of each is not left to what a compiler happens to do: it is
-// computed from the size and the alignment of the types of the fields, and has to be what the compiler does.
-""")
- for struct in wire_structs(functions):
- out.write(f"static_assert(sizeof({struct.name}) == {struct.size});\n")
- out.write(f"static_assert(alignof({struct.name}) == {struct.alignment});\n")
- for field in struct.fields:
- out.write(f"static_assert(offsetof({struct.name}, {field.name}) == {field.offset});\n")
- out.write(f"static_assert(sizeof({struct.name}::{field.name}) == {field.size});\n")
-
-
-def write_wire_struct_layouts(out: TextIO, functions: list) -> None:
- out.write("\nstatic constexpr u32 s_wire_struct_layouts[] = {\n")
- for struct in wire_structs(functions):
- struct_name_hash = wire_layout_name_hash(struct.name)
- out.write(f" // {struct.name}\n")
- out.write(
- f" {struct_name_hash:#010x}u, sizeof({struct.name}), alignof({struct.name}), {len(struct.fields)},\n"
- )
- for field in struct.fields:
- field_name_hash = wire_layout_name_hash(field.name)
- type_name_hash = wire_layout_name_hash(field.cpp_type)
- out.write(
- f" {field_name_hash:#010x}u, {type_name_hash:#010x}u, "
- f"offsetof({struct.name}, {field.name}), sizeof({struct.name}::{field.name}),\n"
- )
- out.write("""};
-
-ReadonlySpan<u32> webgl_wire_struct_layouts()
-{
- return s_wire_struct_layouts;
-}
-""")
-
-
-def write_implementation_file(out: TextIO, functions: list) -> None:
- out.write("""#include <AK/Span.h>
-#include <LibCompositing/WebGL/WebGLCommands.h>
-#include <stddef.h>
-
-namespace Compositing::WebGL {
-""")
- write_wire_struct_layout_assertions(out, functions)
- write_wire_struct_layouts(out, functions)
- out.write("""
-}
-
-u32 const* compositing_webgl_wire_struct_layouts(size_t* out_word_count)
-{
- auto layouts = Compositing::WebGL::webgl_wire_struct_layouts();
- *out_word_count = layouts.size();
- return layouts.data();
-}
-""")
-
-
-if __name__ == "__main__":
- run_generator("Generate WebGL command stream vocabulary", write_header_file, write_implementation_file)
diff --git a/Meta/Generators/generate_libweb_webgl_functions.py b/Meta/Generators/generate_libweb_webgl_functions.py
deleted file mode 100644
index 5cebbfcaa3c..00000000000
--- a/Meta/Generators/generate_libweb_webgl_functions.py
+++ /dev/null
@@ -1,88 +0,0 @@
-#!/usr/bin/env python3
-
-# Copyright (c) 2026, Aliaksandr Kalenik <[email protected]>
-#
-# SPDX-License-Identifier: BSD-2-Clause
-
-import sys
-
-from pathlib import Path
-from typing import TextIO
-
-sys.path.append(str(Path(__file__).resolve().parent))
-
-from libweb_webgl import method_signature
-from libweb_webgl import run_generator
-
-# Generates Web::WebGL::GLFunctions from GLFunctions.json: one member function per GL
-# entry point used by the host WebGL implementation. This is the only place that is
-# allowed to call GL entry points directly; everything above it goes through the methods
-# so the GL boundary stays in one generated, mechanically-verifiable layer.
-
-
-def write_header_file(out: TextIO, functions: list) -> None:
- out.write("""#pragma once
-
-// GL type and enum definitions only -- GL_GLEXT_PROTOTYPES stays undefined here so that
-// nothing outside the generated GLFunctions implementation can call GL directly.
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
-extern "C" {
-#include <GLES2/gl2ext_angle.h>
-}
-#include <GLES3/gl3.h>
-
-#include <LibCompositing/WebGL/Types.h>
-
-namespace Compositing::WebGL {
-
-class GLFunctions {
-public:
-""")
-
- for function in functions:
- if function["category"].startswith("builtin"):
- continue
- out.write(f" {method_signature(function)};\n")
-
- out.write("""};
-
-}
-""")
-
-
-def write_implementation_file(out: TextIO, functions: list) -> None:
- out.write("""#define GL_GLEXT_PROTOTYPES 1
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
-extern "C" {
-#include <GLES2/gl2ext_angle.h>
-}
-#include <GLES3/gl3.h>
-
-#include <LibCompositing/WebGL/GLFunctions.h>
-
-namespace Compositing::WebGL {
-""")
-
- for function in functions:
- if function["category"].startswith("builtin"):
- continue
- forwarded_args = ", ".join(arg["name"] for arg in function["args"])
- call = f"::{function['name']}({forwarded_args})"
- if function["return"] != "void":
- call = "return " + call
- out.write(f"""
-{method_signature(function, "GLFunctions::")}
-{{
- {call};
-}}
-""")
-
- out.write("""
-}
-""")
-
-
-if __name__ == "__main__":
- run_generator("Generate WebGL GL function wrappers", write_header_file, write_implementation_file)
diff --git a/Meta/Generators/libweb_webgl.py b/Meta/Generators/libweb_webgl.py
deleted file mode 100644
index 12009e88d39..00000000000
--- a/Meta/Generators/libweb_webgl.py
+++ /dev/null
@@ -1,253 +0,0 @@
-# Copyright (c) 2026, Aliaksandr Kalenik <[email protected]>
-#
-# SPDX-License-Identifier: BSD-2-Clause
-
-# Shared model and CLI driver for the WebGL generators: loads GLFunctions.json and
-# derives the command-struct shape each annotated GL function serializes to.
-
-import argparse
-import json
-import sys
-
-from dataclasses import dataclass
-from pathlib import Path
-from typing import List
-from typing import Tuple
-
-sys.path.append(str(Path(__file__).resolve().parent.parent))
-
-from Utils.utils import title_case_to_snake_case as snake_case
-
-
-def load_functions(path: str) -> list:
- with open(path, "r", encoding="utf-8") as input_file:
- return json.load(input_file)
-
-
-# All WebGL generators take the same -h/-c/-j arguments and emit one header and one
-# implementation file from the loaded function list.
-def run_generator(description: str, write_header_file, write_implementation_file) -> None:
- parser = argparse.ArgumentParser(description=description, add_help=False)
- parser.add_argument("--help", action="help", help="Show this help message and exit")
- parser.add_argument("-h", "--header", required=True, help="Path to the header file to generate")
- parser.add_argument("-c", "--implementation", required=True, help="Path to the implementation file to generate")
- parser.add_argument("-j", "--json", required=True, help="Path to the JSON file to read from")
- args = parser.parse_args()
-
- functions = load_functions(args.json)
-
- with open(args.header, "w", encoding="utf-8") as output_file:
- write_header_file(output_file, functions)
-
- with open(args.implementation, "w", encoding="utf-8") as output_file:
- write_implementation_file(output_file, functions)
-
-
-def command_name(function: dict) -> str:
- if function["category"].startswith("builtin"):
- return function["name"]
- assert function["name"].startswith("gl")
- return function["name"][2:]
-
-
-def method_name(function: dict) -> str:
- return snake_case(command_name(function))
-
-
-# The GLFunctions and WebGLContextProxy classes must stay signature-identical (the WebGL
-# implementation cannot tell them apart), so both generators emit from this one helper.
-def method_signature(function: dict, qualifier: str = "") -> str:
- args = ", ".join(f"{arg['type']} {arg['name']}" for arg in function["args"])
- return f"{function['return']} {qualifier}{method_name(function)}({args})"
-
-
-# Entries carried by the command stream: regular commands and object creation (struct
-# shapes derived from the GL signature) plus wire-specified ops (custom-handled GL
-# functions and builtins, whose struct shapes are spelled out in the JSON).
-def is_wire_command(function: dict) -> bool:
- return "wire_command" in function
-
-
-def is_wire_sync(function: dict) -> bool:
- return "wire_request" in function
-
-
-def command_stream_entries(functions: list) -> list:
- return [f for f in functions if f["category"] in ("command", "gen") or is_wire_command(f)]
-
-
-def sync_call_entries(functions: list) -> list:
- return [f for f in functions if f["category"] == "sync" or is_wire_sync(f)]
-
-
-def is_pointer(arg: dict) -> bool:
- return arg["type"].endswith("*")
-
-
-def is_const_pointer(arg: dict) -> bool:
- return is_pointer(arg) and "const" in arg["type"]
-
-
-def deref_type(pointer_type: str) -> str:
- return pointer_type.replace("*", "").strip()
-
-
-# Returns the ordered (cpp_type, field_name, arg_or_none) triples of a synchronous
-# call's request struct: every non-out argument, with object ids, strings, and input
-# payloads in their wire representations.
-def sync_request_fields(function: dict) -> list:
- fields = []
- for arg in function["args"]:
- if arg.get("out"):
- continue
- field_name = snake_case(arg["name"])
- if arg.get("object") and not is_pointer(arg):
- fields.append(("WebGLObjectId", field_name, arg))
- elif arg.get("string") or "payload" in arg:
- fields.append(("WebGLDataSpan", field_name, arg))
- else:
- assert not is_pointer(arg), f"unhandled pointer arg {function['name']}.{arg['name']}"
- fields.append((arg["type"], field_name, arg))
- return fields
-
-
-# Returns the ordered (cpp_type, field_name, arg_or_none) triples of a synchronous
-# call's reply struct: the return value, scalar outs by value, buffer outs as spans
-# into the reply's inline data.
-def sync_reply_fields(function: dict) -> list:
- fields = []
- if function["return"] != "void":
- fields.append((function["return"], "return_value", None))
- for arg in function["args"]:
- if not arg.get("out"):
- continue
- field_name = snake_case(arg["name"])
- if "payload" in arg:
- fields.append(("WebGLDataSpan", field_name, arg))
- else:
- fields.append((deref_type(arg["type"]), field_name, arg))
- return fields
-
-
-# Returns the ordered (cpp_type, field_name, arg_or_none) triples of the
-# trivially-copyable struct a command/gen function serializes to.
-def command_struct_fields(function: dict) -> list:
- fields = []
- if function["category"] == "gen" and function["return"] != "void":
- fields.append(("WebGLObjectId", "id", None))
- for arg in function["args"]:
- field_name = snake_case(arg["name"])
- if function["category"] == "gen" and is_pointer(arg) and not is_const_pointer(arg):
- fields.append(("WebGLDataSpan", field_name, arg)) # client-allocated ids
- elif arg.get("object") and not is_pointer(arg):
- fields.append(("WebGLObjectId", field_name, arg))
- elif arg.get("object") and is_const_pointer(arg):
- fields.append(("WebGLDataSpan", field_name, arg)) # array of client ids
- elif arg.get("string"):
- fields.append(("WebGLDataSpan", field_name, arg)) # NUL-terminated bytes
- elif arg.get("offset"):
- fields.append(("GLintptr", field_name, arg))
- elif "payload" in arg:
- if arg.get("nullable"):
- fields.append(("bool", "has_" + field_name, arg))
- fields.append(("WebGLDataSpan", field_name, arg))
- else:
- assert not is_pointer(arg), f"unhandled pointer arg {function['name']}.{arg['name']}"
- fields.append((arg["type"], field_name, arg))
- return fields
-
-
-# Returns the ordered (cpp_type, field_name) pairs of the struct that a command stream entry serializes to.
-def command_wire_fields(function: dict) -> list:
- if is_wire_command(function):
- return [(field["type"], field["name"]) for field in function["wire_command"]]
- return [(cpp_type, field_name) for cpp_type, field_name, _ in command_struct_fields(function)]
-
-
-# Returns the ordered (cpp_type, field_name) pairs of the request struct of a synchronous call.
-def sync_request_wire_fields(function: dict) -> list:
- if is_wire_sync(function):
- return [(field["type"], field["name"]) for field in function["wire_request"]]
- return [(cpp_type, field_name) for cpp_type, field_name, _ in sync_request_fields(function)]
-
-
-# Returns the ordered (cpp_type, field_name) pairs of the reply struct of a synchronous call.
-def sync_reply_wire_fields(function: dict) -> list:
- if is_wire_sync(function):
- return [(field["type"], field["name"]) for field in function["wire_reply"]]
- return [(cpp_type, field_name) for cpp_type, field_name, _ in sync_reply_fields(function)]
-
-
-# The (size, alignment) in bytes of every type that a field of a wire struct can have. Both sides of the command
-# stream are 64-bit, and the generated structs assert that the compiler lays them out as computed from this table.
-WIRE_TYPE_LAYOUTS = {
- "GLenum": (4, 4),
- "GLuint": (4, 4),
- "GLbitfield": (4, 4),
- "GLint": (4, 4),
- "GLsizei": (4, 4),
- "GLfloat": (4, 4),
- "GLboolean": (1, 1),
- "GLintptr": (8, 8),
- "GLsizeiptr": (8, 8),
- "GLuint64": (8, 8),
- "WebGLObjectId": (4, 4),
- "WebGLDataSpan": (8, 4),
- "bool": (1, 1),
- "int": (4, 4),
- "u32": (4, 4),
-}
-
-
-@dataclass
-class WireField:
- cpp_type: str
- name: str
- offset: int
- size: int
-
-
-@dataclass
-class WireStruct:
- # The name of the struct inside the namespace Compositing::WebGL.
- name: str
- fields: List[WireField]
- size: int
- alignment: int
-
-
-def wire_struct(name: str, fields: List[Tuple[str, str]]) -> WireStruct:
- placed_fields = []
- end_of_fields = 0
- alignment = 1
- for cpp_type, field_name in fields:
- if cpp_type not in WIRE_TYPE_LAYOUTS:
- raise ValueError(f"{name}.{field_name} has the type {cpp_type}, which has no entry in WIRE_TYPE_LAYOUTS")
- field_size, field_alignment = WIRE_TYPE_LAYOUTS[cpp_type]
- offset = -(-end_of_fields // field_alignment) * field_alignment
- placed_fields.append(WireField(cpp_type, field_name, offset, field_size))
- end_of_fields = offset + field_size
- alignment = max(alignment, field_alignment)
- # NB: A struct without fields has the size 1 in C++.
- size = max(1, -(-end_of_fields // alignment) * alignment)
- return WireStruct(name, placed_fields, size, alignment)
-
-
-# Every struct that crosses the command stream, in the order of their definition in WebGLCommands.h.
-def wire_structs(functions: list) -> List[WireStruct]:
- structs = []
- for function in command_stream_entries(functions):
- structs.append(wire_struct(f"Commands::{command_name(function)}", command_wire_fields(function)))
- for function in sync_call_entries(functions):
- name = command_name(function)
- structs.append(wire_struct(f"SyncCalls::{name}::Request", sync_request_wire_fields(function)))
- structs.append(wire_struct(f"SyncCalls::{name}::Reply", sync_reply_wire_fields(function)))
- return structs
-
-
-# The 32-bit FNV-1a hash that stands for the name of a struct, a field or a type in the table of layout words.
-def wire_layout_name_hash(name: str) -> int:
- hash_value = 0x811C9DC5
- for byte in name.encode("utf-8"):
- hash_value = ((hash_value ^ byte) * 0x01000193) & 0xFFFFFFFF
- return hash_value