Truly independent web browser
LibCompositing: Remove the C++ encoder of the WebGL command stream
Jelle Raaijmakers351d87fe5305
diff --git a/Libraries/LibCompositing/WebGL/WebGLCommandList.cpp b/Libraries/LibCompositing/WebGL/WebGLCommandList.cppindex 598e8fd411d..4c71f261212 100644--- a/Libraries/LibCompositing/WebGL/WebGLCommandList.cpp+++ b/Libraries/LibCompositing/WebGL/WebGLCommandList.cpp@@ -4,12 +4,11 @@* SPDX-License-Identifier: BSD-2-Clause*/-#include <AK/NumericLimits.h>#include <LibCompositing/WebGL/WebGLCommandList.h>namespace Compositing::WebGL {-static size_t payload_layout_size(ReadonlyBytes payload, ReadonlyBytes inline_data, ReadonlyBytes more_inline_data = {})+static size_t payload_layout_size(ReadonlyBytes payload, ReadonlyBytes inline_data, ReadonlyBytes more_inline_data){auto size = payload.size();if (!inline_data.is_empty())@@ -19,7 +18,7 @@ static size_t payload_layout_size(ReadonlyBytes payload, ReadonlyBytes inline_dareturn size;}-static void write_payload(Bytes destination, ReadonlyBytes payload, ReadonlyBytes inline_data, ReadonlyBytes more_inline_data = {})+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();@@ -34,53 +33,6 @@ static void write_payload(Bytes destination, ReadonlyBytes payload, ReadonlyByte__builtin_memset(destination.offset_pointer(cursor), 0, destination.size() - cursor);}-size_t WebGLCommandList::padded_record_size(ReadonlyBytes payload, ReadonlyBytes inline_data)-{- return align_up_to(sizeof(WebGLCommandHeader) + payload_layout_size(payload, inline_data), command_alignment);-}--void WebGLCommandList::write_record(Bytes destination, WebGLCommandType type, ReadonlyBytes payload, ReadonlyBytes inline_data)-{- VERIFY(destination.size() == padded_record_size(payload, inline_data));-- auto padded_payload_size = destination.size() - sizeof(WebGLCommandHeader);- VERIFY(padded_payload_size <= NumericLimits<u32>::max());-- WebGLCommandHeader header {- .type = type,- .payload_size = static_cast<u32>(padded_payload_size),- };-- __builtin_memcpy(destination.data(), &header, sizeof(header));- write_payload(destination.slice(sizeof(header)), payload, inline_data);-}--void WebGLCommandList::append_bytes(WebGLCommandType type, ReadonlyBytes payload, ReadonlyBytes inline_data)-{- VERIFY(m_bytes.size() % command_alignment == 0);-- auto record_size = padded_record_size(payload, inline_data);- auto record_offset = m_bytes.size();- m_bytes.resize(record_offset + record_size);- write_record(m_bytes.bytes().slice(record_offset), type, payload, inline_data);-}--ByteBuffer WebGLSyncCall::encode_request_bytes(WebGLSyncCallType type, ReadonlyBytes request, ReadonlyBytes inline_data)-{- auto padded_payload_size = align_up_to(payload_layout_size(request, inline_data), WebGLCommandList::command_alignment);- VERIFY(padded_payload_size <= NumericLimits<u32>::max());-- WebGLSyncCallHeader header {- .type = type,- .payload_size = static_cast<u32>(padded_payload_size),- };-- auto bytes = MUST(ByteBuffer::create_uninitialized(sizeof(header) + padded_payload_size));- __builtin_memcpy(bytes.data(), &header, sizeof(header));- write_payload(bytes.bytes().slice(sizeof(header)), request, inline_data);- return bytes;-}-ByteBuffer WebGLSyncCall::encode_reply_bytes(ReadonlyBytes reply, ReadonlyBytes inline_data, ReadonlyBytes more_inline_data){VERIFY(more_inline_data.is_empty() || !inline_data.is_empty());diff --git a/Libraries/LibCompositing/WebGL/WebGLCommandList.h b/Libraries/LibCompositing/WebGL/WebGLCommandList.hindex bad34a7909c..0842aa00b21 100644--- a/Libraries/LibCompositing/WebGL/WebGLCommandList.h+++ b/Libraries/LibCompositing/WebGL/WebGLCommandList.h@@ -36,17 +36,6 @@ public:return static_cast<u32>(align_up_to(previous.offset + previous.size, command_alignment));}- template<typename Command>- void append(Command const& command, ReadonlyBytes inline_data = {})- {- append_bytes(Command::command_type, { &command, sizeof(command) }, inline_data);- }-- void append_bytes(WebGLCommandType, ReadonlyBytes payload, ReadonlyBytes inline_data);-- static size_t padded_record_size(ReadonlyBytes payload, ReadonlyBytes inline_data);- static void write_record(Bytes destination, WebGLCommandType, ReadonlyBytes payload, ReadonlyBytes inline_data);-template<typename Callback>static ErrorOr<void> for_each_command(ReadonlyBytes bytes, Callback&& callback){@@ -96,22 +85,6 @@ public:VERIFY(bytes[bytes.size() - 1] == 0);return bytes;}-- static void copy_data_span(ReadonlyBytes payload, WebGLDataSpan span, Bytes destination)- {- auto resolved = resolve_data_span(payload, span);- VERIFY(resolved.size() <= destination.size());- __builtin_memcpy(destination.data(), resolved.data(), resolved.size());- }-- ReadonlyBytes bytes() const { return m_bytes; }- ByteBuffer const& buffer() const { return m_bytes; }- void clear_with_capacity() { m_bytes.set_size(0); }- bool is_empty() const { return m_bytes.is_empty(); }- size_t size_in_bytes() const { return m_bytes.size(); }--private:- ByteBuffer m_bytes;};struct WebGLSyncCallHeader {@@ -122,12 +95,6 @@ static_assert(IsTriviallyCopyable<WebGLSyncCallHeader>);class COMPOSITING_API WebGLSyncCall {public:- template<typename Call>- static ByteBuffer encode_request(typename Call::Request const& request, ReadonlyBytes inline_data = {})- {- return encode_request_bytes(Call::call_type, { &request, sizeof(request) }, inline_data);- }-template<typename Callback>static ErrorOr<ByteBuffer> dispatch_request(ReadonlyBytes bytes, Callback&& callback){@@ -155,17 +122,7 @@ public:return encode_reply_bytes({ &reply, sizeof(reply) }, inline_data, more_inline_data);}- template<typename Reply>- static Reply decode_reply(ReadonlyBytes bytes)- {- VERIFY(bytes.size() >= sizeof(Reply));- Reply reply;- __builtin_memcpy(&reply, bytes.data(), sizeof(reply));- return reply;- }-private:- static ByteBuffer encode_request_bytes(WebGLSyncCallType, ReadonlyBytes request, ReadonlyBytes inline_data);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.hindex 517b9d79d00..bd2986fbbfa 100644--- a/Libraries/LibCompositing/WebGL/WebGLSharedCommandBuffer.h+++ b/Libraries/LibCompositing/WebGL/WebGLSharedCommandBuffer.h@@ -23,12 +23,6 @@ public:WebGLSharedCommandBuffer() = default;- static ErrorOr<WebGLSharedCommandBuffer> create(size_t data_region_capacity = default_data_region_capacity)- {- auto buffer = TRY(Core::AnonymousBuffer::create_with_size(data_region_offset + data_region_capacity));- return WebGLSharedCommandBuffer { move(buffer) };- }-static Optional<WebGLSharedCommandBuffer> adopt_received_buffer(Core::AnonymousBuffer buffer){if (!buffer.is_valid() || buffer.size() <= data_region_offset)@@ -37,23 +31,12 @@ public:}bool is_valid() const { return m_buffer.is_valid(); }- Core::AnonymousBuffer const& buffer() const { return m_buffer; }-- u64 executed_flush_sequence_number() const- {- return reinterpret_cast<Atomic<u64> const*>(m_buffer.data<u8>())->load(AK::MemoryOrder::memory_order_acquire);- }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);}- Bytes data_region()- {- return { m_buffer.data<u8>() + data_region_offset, m_buffer.size() - data_region_offset };- }-ReadonlyBytes data_region() const{return { m_buffer.data<u8>() + data_region_offset, m_buffer.size() - data_region_offset };diff --git a/Libraries/LibWeb/WebGL/Types.h b/Libraries/LibWeb/WebGL/Types.hindex e3f6be61609..0daa6d2dbfb 100644--- a/Libraries/LibWeb/WebGL/Types.h+++ b/Libraries/LibWeb/WebGL/Types.h@@ -33,7 +33,6 @@ using Compositing::WebGL::PixelUnpackState;using Compositing::WebGL::ReadPixelsResult;using Compositing::WebGL::required_2d_texture_data_size;using Compositing::WebGL::texture_export_format;-using Compositing::WebGL::to_string;using Compositing::WebGL::WebGLCommandHeader;using Compositing::WebGL::WebGLCommandList;using Compositing::WebGL::WebGLCommandType;diff --git a/Meta/Generators/generate_libweb_webgl_commands.py b/Meta/Generators/generate_libweb_webgl_commands.pyindex f22fa7c96f5..b6ad56c4684 100644--- a/Meta/Generators/generate_libweb_webgl_commands.py+++ b/Meta/Generators/generate_libweb_webgl_commands.py@@ -42,8 +42,6 @@ enum class {enum_name} : u16 {{}};inline constexpr u16 {count_name} = {len(names)};--COMPOSITING_API StringView to_string({enum_name});""")@@ -72,22 +70,6 @@ def write_static_asserts(out: TextIO, macro: str, assert_body: str) -> None:""")-def write_to_string_implementation(out: TextIO, macro: str, enum_name: str) -> None:- out.write(f"""-StringView to_string({enum_name} type)-{{- switch (type) {{-#define __ENUMERATE(name) \\- case {enum_name}::name: \\- return #name##sv;- {macro}(__ENUMERATE)-#undef __ENUMERATE- }}- VERIFY_NOT_REACHED();-}}-""")--def write_header_file(out: TextIO, functions: list) -> None:commands = command_stream_entries(functions)sync_calls = sync_call_entries(functions)@@ -97,7 +79,6 @@ def write_header_file(out: TextIO, functions: list) -> None:#include <AK/Assertions.h>#include <AK/Span.h>#include <AK/StdLibExtras.h>-#include <AK/StringView.h>#include <AK/Types.h>#include <LibCompositing/Export.h>#include <LibCompositing/WebGL/GLFunctions.h>@@ -116,7 +97,6 @@ namespace Compositing::WebGL {for f in commands:name = command_name(f)out.write(f"\nstruct {name} {{\n")- out.write(f" static constexpr auto command_type = WebGLCommandType::{name};\n")for cpp_type, field_name in command_wire_fields(f):out.write(f" {cpp_type} {field_name} {{}};\n")out.write("};\n")@@ -136,7 +116,6 @@ namespace Compositing::WebGL {for f in sync_calls:name = command_name(f)out.write(f"\nstruct {name} {{\n")- out.write(f" static constexpr auto call_type = WebGLSyncCallType::{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")@@ -213,8 +192,6 @@ def write_implementation_file(out: TextIO, functions: list) -> None:namespace Compositing::WebGL {""")- write_to_string_implementation(out, "ENUMERATE_WEBGL_COMMANDS", "WebGLCommandType")- write_to_string_implementation(out, "ENUMERATE_WEBGL_SYNC_CALLS", "WebGLSyncCallType")write_wire_struct_layout_assertions(out, functions)write_wire_struct_layouts(out, functions)out.write("""