Skip to content

Truly independent web browser

LibCompositing+LibWeb+Compositor: Send a display list as one value

Aliaksandr Kalenik0798ffb4b3dc
diff --git a/Libraries/LibCompositing/CMakeLists.txt b/Libraries/LibCompositing/CMakeLists.txt
index 4d93d759ad6..0370d7da39c 100644
--- a/Libraries/LibCompositing/CMakeLists.txt
+++ b/Libraries/LibCompositing/CMakeLists.txt
@@ -27,7 +27,6 @@ compile_ipc(${LADYBIRD_SOURCE_DIR}/Services/Compositor/CompositorWebContentClien
compile_ipc(${LADYBIRD_SOURCE_DIR}/Services/Compositor/CompositorWebContentServer.ipc ${CMAKE_BINARY_DIR}/Services/Compositor/CompositorWebContentServerEndpoint.h)
compile_ipc(${LADYBIRD_SOURCE_DIR}/Services/Compositor/RenderClockClient.ipc ${CMAKE_BINARY_DIR}/Services/Compositor/RenderClockClientEndpoint.h)
compile_ipc(${LADYBIRD_SOURCE_DIR}/Services/Compositor/RenderClockServer.ipc ${CMAKE_BINARY_DIR}/Services/Compositor/RenderClockServerEndpoint.h)
-compile_ipc(DisplayList/DisplayListProperties.ipc DisplayList/DisplayListPropertiesCodecs.h)
compile_ipc(Types.ipc TypesCodecs.h)
compile_ipc(FontClient.ipc FontClientEndpoint.h)
compile_ipc(FontServer.ipc FontServerEndpoint.h)
diff --git a/Libraries/LibCompositing/DisplayList/DisplayListProperties.ipc b/Libraries/LibCompositing/DisplayList/DisplayListProperties.ipc
index 9f09c05853a..2f3c3f3c0e9 100644
--- a/Libraries/LibCompositing/DisplayList/DisplayListProperties.ipc
+++ b/Libraries/LibCompositing/DisplayList/DisplayListProperties.ipc
@@ -2,12 +2,8 @@
//
// SPDX-License-Identifier: BSD-2-Clause
-// NB: The IPC compiler cannot check that each struct here lists every field of its C++ type. A field left out
-// here does not cross IPC.
+// What travels beside a display list's tape, which only Rust sends and receives.
-#include <LibCompositing/DisplayList/DisplayListProperties.h>
-
-[ExistingCpp]
struct Compositing::AsyncScrollingMetadata {
Optional<Web::UniqueNodeID> document_id;
Gfx::IntRect viewport_rect;
@@ -20,7 +16,6 @@ struct Compositing::AsyncScrollingMetadata {
Compositing::KeyboardScrollState keyboard_scroll_state;
}
-[ExistingCpp]
struct Compositing::DisplayListProperties {
u64 id;
u64 compatible_visual_context_tree_structural_epoch;
diff --git a/Libraries/LibCompositing/Rust/src/ipc_types.rs b/Libraries/LibCompositing/Rust/src/ipc_types.rs
index 8af8e0e06b3..67fb5be50d0 100644
--- a/Libraries/LibCompositing/Rust/src/ipc_types.rs
+++ b/Libraries/LibCompositing/Rust/src/ipc_types.rs
@@ -28,6 +28,7 @@ pub type Gfx_FloatRect = libgfx_rust::FloatRect;
pub type Gfx_Color = libgfx_rust::Color;
pub type Compositing_VisualContextTree = Arc<VisualContextTree>;
pub type Compositing_ScrollStateSnapshot = crate::scrolling::ScrollStateSnapshot;
+pub type Compositing_DisplayList = SharedDisplayList;
impl Encode for CompositorContextId {
fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {
@@ -155,6 +156,39 @@ impl Decode for Core_AnonymousBuffer {
}
}
+/// `Compositing::DisplayList`: a display list on its way to the compositor, with its tape and run table packed in shared
+/// memory, which the compositor copies out of it, and what travels beside them.
+#[derive(Debug)]
+pub struct SharedDisplayList {
+ pub packed_tape: Core_AnonymousBuffer,
+ pub tape_size: u64,
+ pub run_count: u64,
+ pub properties: Compositing_DisplayListProperties,
+ pub async_scrolling_metadata: Option<Compositing_AsyncScrollingMetadata>,
+}
+
+impl Encode for SharedDisplayList {
+ fn encode(&self, encoder: &mut Encoder) -> Result<(), EncodeError> {
+ encoder.encode(&self.packed_tape)?;
+ encoder.encode(&self.tape_size)?;
+ encoder.encode(&self.run_count)?;
+ encoder.encode(&self.properties)?;
+ encoder.encode(&self.async_scrolling_metadata)
+ }
+}
+
+impl Decode for SharedDisplayList {
+ fn decode(decoder: &mut Decoder<'_>) -> Result<Self, DecodeError> {
+ Ok(Self {
+ packed_tape: decoder.decode()?,
+ tape_size: decoder.decode()?,
+ run_count: decoder.decode()?,
+ properties: decoder.decode()?,
+ async_scrolling_metadata: decoder.decode()?,
+ })
+ }
+}
+
/// A display list that another one nests, with the tree it was recorded against.
#[derive(Clone)]
pub struct NestedDisplayListResource {
diff --git a/Libraries/LibWeb/Rust/src/paint_stage.rs b/Libraries/LibWeb/Rust/src/paint_stage.rs
index 12a5765d1e9..16444f1306b 100644
--- a/Libraries/LibWeb/Rust/src/paint_stage.rs
+++ b/Libraries/LibWeb/Rust/src/paint_stage.rs
@@ -12,9 +12,12 @@
//! present a frame: it has no [`Presenting`] to present with.
use crate::painting::display_list::commands::CompositorContextId;
+use crate::painting::display_list::storage::DisplayListStorage;
use crate::render_state::SampledFrame;
use crate::stage_thread::{InFlight, Relay, Riding, StageThread};
-use libcompositing_rust::ipc_types::Core_AnonymousBuffer;
+use libcompositing_rust::ipc_types::{
+ Compositing_AsyncScrollingMetadata, Compositing_DisplayListProperties, Core_AnonymousBuffer, SharedDisplayList,
+};
use libgfx_rust::font::FontHandle;
use libgfx_rust::image_frame::ImageFrameHandle;
use libipc_rust::cpp_connection::{FfiThreadSafeMessagePoster, ThreadSafeMessagePoster};
@@ -108,13 +111,28 @@ impl CompositorPoster {
}
}
+ /// The display list `storage` holds, with `properties` and `async_scrolling_metadata`, as a message carries it, or none
+ /// where its tape cannot be placed in shared memory.
+ pub(crate) fn share_display_list(
+ &self,
+ storage: &DisplayListStorage,
+ properties: Compositing_DisplayListProperties,
+ async_scrolling_metadata: Option<Compositing_AsyncScrollingMetadata>,
+ ) -> Option<SharedDisplayList> {
+ let packed_tape =
+ self.shared_buffer_with(storage.packed_size(), |destination| storage.write_packed(destination))?;
+ Some(SharedDisplayList {
+ packed_tape,
+ tape_size: storage.bytes().len() as u64,
+ run_count: storage.command_runs().len() as u64,
+ properties,
+ async_scrolling_metadata,
+ })
+ }
+
/// Shared memory of `size` bytes that `write` fills, as a message carries it, or none where it cannot be made. The
/// memory is sealed where the platform supports it, so the receiver cannot be faulted by the file shrinking.
- pub(crate) fn shared_buffer_with(
- &self,
- size: usize,
- write: impl FnOnce(&mut [u8]),
- ) -> Option<Core_AnonymousBuffer> {
+ fn shared_buffer_with(&self, size: usize, write: impl FnOnce(&mut [u8])) -> Option<Core_AnonymousBuffer> {
if size == 0 {
return Some(Core_AnonymousBuffer { shared_memory: None });
}
diff --git a/Libraries/LibWeb/Rust/src/painting/presentation.rs b/Libraries/LibWeb/Rust/src/painting/presentation.rs
index 7db65f5419c..e6230cf1a6e 100644
--- a/Libraries/LibWeb/Rust/src/painting/presentation.rs
+++ b/Libraries/LibWeb/Rust/src/painting/presentation.rs
@@ -736,15 +736,11 @@ fn post_frame_through(poster: &crate::paint_stage::CompositorPoster, frame: Comp
.clone()
.unwrap_or_else(|| Arc::new(VisualContextTree::create_identity())),
);
- match poster.shared_buffer_with(storage.packed_size(), |destination| storage.write_packed(destination)) {
- Some(display_list_buffer) => {
+ match poster.share_display_list(&storage, update.properties, Some(update.async_scrolling_metadata)) {
+ Some(display_list) => {
let message = UpdateDisplayList {
context_id,
- display_list_buffer,
- tape_size: storage.bytes().len() as u64,
- run_count: storage.command_runs().len() as u64,
- display_list_properties: update.properties,
- async_scrolling_metadata: Some(update.async_scrolling_metadata),
+ display_list,
visual_context_tree: update.visual_context_tree,
resource_transaction: update.resources.transaction,
scroll_state: update.scroll_state,
diff --git a/Libraries/LibWeb/Rust/src/painting/rasterize.rs b/Libraries/LibWeb/Rust/src/painting/rasterize.rs
index 2d7bd772017..ba9f613f56b 100644
--- a/Libraries/LibWeb/Rust/src/painting/rasterize.rs
+++ b/Libraries/LibWeb/Rust/src/painting/rasterize.rs
@@ -149,9 +149,13 @@ fn post_rasterization(
}
let tree = Arc::new(VisualContextTree::create_identity());
let storage = DisplayListStorage::recorded(Arc::new(display_list), tree.clone());
- let Some(display_list_buffer) =
- poster.shared_buffer_with(storage.packed_size(), |destination| storage.write_packed(destination))
- else {
+ let properties = Compositing_DisplayListProperties {
+ id: allocate_display_list_id(),
+ compatible_visual_context_tree_structural_epoch: tree.structural_epoch,
+ surface_clear_color: None,
+ root_group_color: libgfx_rust::Color::TRANSPARENT,
+ };
+ let Some(display_list) = poster.share_display_list(&storage, properties, None) else {
eprintln!(
"WebContent: Could not place a {} byte display list to rasterize in shared memory",
storage.bytes().len()
@@ -160,15 +164,7 @@ fn post_rasterization(
};
poster.post(RasterizeDisplayList {
token,
- display_list_buffer,
- tape_size: storage.bytes().len() as u64,
- run_count: storage.command_runs().len() as u64,
- display_list_properties: Compositing_DisplayListProperties {
- id: allocate_display_list_id(),
- compatible_visual_context_tree_structural_epoch: tree.structural_epoch,
- surface_clear_color: None,
- root_group_color: libgfx_rust::Color::TRANSPARENT,
- },
+ display_list,
visual_context_tree: tree,
nested_display_lists: Compositing_DisplayListResourceTransaction {
display_lists: resources
diff --git a/Services/Compositor/CompositorWebContentServer.ipc b/Services/Compositor/CompositorWebContentServer.ipc
index eb539cf922d..09c3703f3b3 100644
--- a/Services/Compositor/CompositorWebContentServer.ipc
+++ b/Services/Compositor/CompositorWebContentServer.ipc
@@ -1,7 +1,6 @@
#include <AK/NonnullRefPtr.h>
#include <AK/Optional.h>
#include <LibCompositing/DisplayList/Canvas2DCommandStream.h>
-#include <LibCompositing/DisplayList/DisplayListProperties.h>
#include <LibCompositing/DisplayList/DisplayListResourceStorage.h>
#include <LibCompositing/Forward.h>
#include <LibCompositing/Types.h>
@@ -43,7 +42,7 @@ endpoint CompositorWebContentServer
// The fonts and image frames that a display list or a visual context tree draws go ahead of it, in
// update_display_list_resources, and the resource transaction that comes with it holds none. Only Rust sends and
// receives the display lists, the visual context trees and the scroll state snapshots.
- [RustReceiver, RustSender] update_display_list(Web::CompositorContextId context_id, Core::AnonymousBuffer display_list_buffer, u64 tape_size, u64 run_count, Compositing::DisplayListProperties display_list_properties, Optional<Compositing::AsyncScrollingMetadata> async_scrolling_metadata, Compositing::VisualContextTree visual_context_tree, Compositing::DisplayListResourceTransaction resource_transaction, Compositing::ScrollStateSnapshot scroll_state) =|
+ [RustReceiver, RustSender] update_display_list(Web::CompositorContextId context_id, Compositing::DisplayList display_list, Compositing::VisualContextTree visual_context_tree, Compositing::DisplayListResourceTransaction resource_transaction, Compositing::ScrollStateSnapshot scroll_state) =|
update_display_list_resources(Web::CompositorContextId context_id, Compositing::DisplayListResourceTransaction resource_transaction) =|
[RustReceiver, RustSender] update_visual_context_tree(Web::CompositorContextId context_id, Compositing::VisualContextTree visual_context_tree, Compositing::DisplayListResourceTransaction resource_transaction, Compositing::ScrollStateSnapshot scroll_state, Compositing::KeyboardScrollState keyboard_scroll_state) =|
[RustReceiver, RustSender] update_scroll_state(Web::CompositorContextId context_id, Compositing::ScrollStateSnapshot scroll_state, Compositing::KeyboardScrollState keyboard_scroll_state) =|
@@ -68,7 +67,7 @@ endpoint CompositorWebContentServer
// a token that the next rasterize_display_list names, and with the display lists it nests, which come with it. The
// compositor answers with did_rasterize_display_list().
stage_rasterization(u64 token, Compositing::DisplayListResourceTransaction resources, Gfx::ShareableBitmap target_bitmap) =|
- [RustReceiver, RustSender] rasterize_display_list(u64 token, Core::AnonymousBuffer display_list_buffer, u64 tape_size, u64 run_count, Compositing::DisplayListProperties display_list_properties, Compositing::VisualContextTree visual_context_tree, Compositing::DisplayListResourceTransaction nested_display_lists) =|
+ [RustReceiver, RustSender] rasterize_display_list(u64 token, Compositing::DisplayList display_list, Compositing::VisualContextTree visual_context_tree, Compositing::DisplayListResourceTransaction nested_display_lists) =|
create_webgl_context(Compositing::WebGL::WebGLVersion webgl_version, Gfx::IntSize size, bool depth, bool stencil, bool antialias) => (bool success, Compositing::CanvasId canvas_id, Vector<String> supported_extensions)
webgl_set_command_buffer(Compositing::CanvasId canvas_id, Core::AnonymousBuffer command_buffer) =|
diff --git a/Services/Compositor/Rust/src/core/messages.rs b/Services/Compositor/Rust/src/core/messages.rs
index 21de36d57af..391bc2b0fba 100644
--- a/Services/Compositor/Rust/src/core/messages.rs
+++ b/Services/Compositor/Rust/src/core/messages.rs
@@ -28,7 +28,7 @@ use libcompositing_rust::ipc_types::compositor_web_content_server::messages::{
};
use libcompositing_rust::ipc_types::{
Compositing_WheelEventAnswer as WheelEventAnswer, Compositing_WheelStepLetThrough as WheelStepLetThrough,
- compositor_presentation_server, compositor_web_content_server,
+ SharedDisplayList, compositor_presentation_server, compositor_web_content_server,
};
use libcompositing_rust::scrolling::async_scrolling_state::AsyncScrollOperationID;
use libcompositing_rust::scrolling::{AccumulatedVisualContextTree, DisplayList};
@@ -215,11 +215,14 @@ impl MessagesFromWebContent<'_> {
raster.discard_staged_rasterization(client, token);
Ok(false)
};
- let storage = match raster.receive_display_list_storage(
- message.display_list_buffer,
- message.tape_size,
- message.run_count,
- ) {
+ let SharedDisplayList {
+ packed_tape,
+ tape_size,
+ run_count,
+ properties,
+ ..
+ } = message.display_list;
+ let storage = match raster.receive_display_list_storage(packed_tape, tape_size, run_count) {
Ok(storage) => storage,
Err(error) => {
let _ = writeln!(
@@ -241,7 +244,6 @@ impl MessagesFromWebContent<'_> {
nested_display_lists.add(display_list);
}
let tree = message.visual_context_tree;
- let properties = message.display_list_properties;
if properties.compatible_visual_context_tree_structural_epoch != tree.structural_epoch
|| !tree.display_list_references_only_live_nodes(storage.command_runs())
{
@@ -282,12 +284,18 @@ impl MessagesFromWebContent<'_> {
impl compositor_web_content_server::Stub for MessagesFromWebContent<'_> {
fn update_display_list(&mut self, message: UpdateDisplayList) -> Result<(), Misbehavior> {
let started_at = std::time::Instant::now();
- let tape_size = message.tape_size;
- let storage = match self.core.raster().receive_display_list_storage(
- message.display_list_buffer,
- message.tape_size,
- message.run_count,
- ) {
+ let SharedDisplayList {
+ packed_tape,
+ tape_size,
+ run_count,
+ properties,
+ async_scrolling_metadata,
+ } = message.display_list;
+ let storage = match self
+ .core
+ .raster()
+ .receive_display_list_storage(packed_tape, tape_size, run_count)
+ {
Ok(storage) => storage,
Err(error) => {
let _ = writeln!(
@@ -304,7 +312,6 @@ impl compositor_web_content_server::Stub for MessagesFromWebContent<'_> {
if !self.context_is_owned_by_sender(message.context_id)? {
return Ok(());
}
- let properties = message.display_list_properties;
if properties.compatible_visual_context_tree_structural_epoch != tree.structural_epoch {
let _ = writeln!(
std::io::stderr(),
@@ -326,7 +333,7 @@ impl compositor_web_content_server::Stub for MessagesFromWebContent<'_> {
storage,
properties.id,
properties.compatible_visual_context_tree_structural_epoch,
- message.async_scrolling_metadata,
+ async_scrolling_metadata,
properties.surface_clear_color,
properties.root_group_color,
);