Truly independent web browser
Everywhere: Name remote layers by a host handle
Aliaksandr Kalenik8a8d55603659
diff --git a/Libraries/LibCompositing/Types.ipc b/Libraries/LibCompositing/Types.ipcindex 34ce233f3b8..44233383cf2 100644--- a/Libraries/LibCompositing/Types.ipc+++ b/Libraries/LibCompositing/Types.ipc@@ -20,6 +20,18 @@ enum Compositing::ContextVisibility : u8 {Hidden,}+[ExistingCpp]+enum Compositing::RemoteLayerHostKind : u8 {+ None,+ CoreAnimationContext,+}++[ExistingCpp]+struct Compositing::RemoteLayerHostHandle {+ Compositing::RemoteLayerHostKind kind;+ u64 id;+}+[ExistingCpp]enum Compositing::ScrollAnimationKind : u8 {SmoothScroll = 0,diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cppindex ac7ffb97c19..570b5f53860 100644--- a/Libraries/LibWebView/Application.cpp+++ b/Libraries/LibWebView/Application.cpp@@ -1529,10 +1529,10 @@ Optional<Application::RemoteLayer> Application::create_remote_layer()auto response = m_compositor_client->try_create_remote_layer(m_compositor_presentation_id, remote_layer_id);if (response.is_error())return {};- auto core_animation_context_id = response.release_value();- if (core_animation_context_id == 0)+ auto host_handle = response.release_value();+ if (host_handle.kind == Compositing::RemoteLayerHostKind::None)return {};- return RemoteLayer { .id = remote_layer_id, .core_animation_context_id = core_animation_context_id };+ return RemoteLayer { .id = remote_layer_id, .host_handle = host_handle };}void Application::destroy_remote_layer(u64 remote_layer_id)diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.hindex 5e50d143565..4ad1226d1ae 100644--- a/Libraries/LibWebView/Application.h+++ b/Libraries/LibWebView/Application.h@@ -271,7 +271,7 @@ public:struct RemoteLayer {u64 id { 0 };- u32 core_animation_context_id { 0 };+ Compositing::RemoteLayerHostHandle host_handle;};// None where the Compositor offers no remote layers, or is gone.Optional<RemoteLayer> create_remote_layer();diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cppindex a987fd68931..5b7577b2e2b 100644--- a/Libraries/LibWebView/ViewImplementation.cpp+++ b/Libraries/LibWebView/ViewImplementation.cpp@@ -464,20 +464,20 @@ void ViewImplementation::set_hosts_remote_layer(bool hosts_remote_layer)if (!hosts_remote_layer) {if (auto remote_layer_id = exchange(m_remote_layer_id, {}); remote_layer_id.has_value()) {Application::the().destroy_remote_layer(*remote_layer_id);- did_create_remote_layer(0);+ did_create_remote_layer({});}return;}auto remote_layer = Application::the().create_remote_layer();if (!remote_layer.has_value()) {- did_create_remote_layer(0);+ did_create_remote_layer({});return;}m_remote_layer_id = remote_layer->id;update_remote_layer_fit();Application::the().show_context_in_remote_layer(remote_layer->id, page().compositor_context_id());- did_create_remote_layer(remote_layer->core_animation_context_id);+ did_create_remote_layer(remote_layer->host_handle);}void ViewImplementation::take_frame_snapshot(Optional<Gfx::IntSize> maximum_size, Function<void(Optional<Gfx::ShareableBitmap>)> callback)diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.hindex afb176efad5..0970b541227 100644--- a/Libraries/LibWebView/ViewImplementation.h+++ b/Libraries/LibWebView/ViewImplementation.h@@ -777,7 +777,7 @@ protected:virtual void did_accept_presented_backing_store(i32, Gfx::IntRect) { }// The view's remote layer was made, or made again. The ID is 0 when there is none, and frames arrive in backing// stores instead.- virtual void did_create_remote_layer(u32 core_animation_context_id) { (void)core_animation_context_id; }+ virtual void did_create_remote_layer(Compositing::RemoteLayerHostHandle) { }virtual void did_present_frame_in_remote_layer(Gfx::IntSize, double device_pixel_ratio) { (void)device_pixel_ratio; }virtual void did_hold_synchronized_resize_frame(u64 token) { (void)token; }virtual void did_commit_synchronized_resize(u64 token) { (void)token; }diff --git a/Services/Compositor/CompositorControlServer.ipc b/Services/Compositor/CompositorControlServer.ipcindex 4ea75f987b7..567dcedd807 100644--- a/Services/Compositor/CompositorControlServer.ipc+++ b/Services/Compositor/CompositorControlServer.ipc@@ -17,8 +17,8 @@ endpoint CompositorControlServerconnect_video_presentation(i32 web_content_connection_id, IPC::TransportHandle handle) =|create_presentation_connection(bool synthesizes_scroll_momentum, bool scrolls_elastically, Optional<u64> gpu_presentation_adapter_luid) => (IPC::TransportHandle handle, u64 presentation_id)bind_presentation(Web::CompositorContextId context_id, u64 presentation_id) => ()- // The ID of the layer's CoreAnimation context is 0 where the platform has no remote layers.- create_remote_layer(u64 presentation_id, u64 remote_layer_id) => (u32 core_animation_context_id)+ // The host handle's kind is None where the presentation has no remote layers.+ create_remote_layer(u64 presentation_id, u64 remote_layer_id) => (Compositing::RemoteLayerHostHandle host_handle)destroy_remote_layer(u64 remote_layer_id) =|show_context_in_remote_layer(u64 remote_layer_id, Optional<Web::CompositorContextId> context_id) =|set_remote_layer_fit(u64 remote_layer_id, Optional<Gfx::IntSize> fit_within) =|diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cppindex 26bceb1dc3f..0bff3214551 100644--- a/Services/Compositor/CompositorState.cpp+++ b/Services/Compositor/CompositorState.cpp@@ -199,23 +199,22 @@ void CompositorState::unbind_presentation(Web::CompositorContextId context_id)schedule_pending_present_frame_if_unblocked(context_id, *context);}-u32 CompositorState::create_remote_layer(CompositorStateClient& presentation, u64 remote_layer_id)+Compositing::RemoteLayerHostHandle CompositorState::create_remote_layer(CompositorStateClient& presentation, u64 remote_layer_id){VERIFY(m_presentations.contains(&presentation));if (auto existing = m_remote_layers.find(remote_layer_id); existing != m_remote_layers.end()) {dbgln("Compositor: Ignoring creation of remote layer {}, which already exists", remote_layer_id);- return 0;+ return {};}auto window_server = m_window_servers.get(&presentation);if (!window_server.has_value())- return 0;+ return {};auto layer = (*window_server)->try_create_remote_layer(remote_layer_id);if (!layer)- return 0;+ return {};auto host_handle = layer->host_handle();- VERIFY(host_handle.kind == Compositing::RemoteLayerHostKind::CoreAnimationContext);m_remote_layers.set(remote_layer_id, { .presentation = &presentation, .window_server = **window_server, .layer = move(layer), .shown_context_id = {}, .fit_within = {}, .size_of_shown_frame_laid_out_by_page = {} });- return static_cast<u32>(host_handle.id);+ return host_handle;}void CompositorState::destroy_remote_layer(u64 remote_layer_id)diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.hindex 881a8c40505..6eaea41133b 100644--- a/Services/Compositor/CompositorState.h+++ b/Services/Compositor/CompositorState.h@@ -167,8 +167,8 @@ public:void set_scrollbar_track_press_jumps(CompositorStateClient&, bool jumps);// A remote layer shows the frames of one root context at a time, in a view of the presentation it was created- // for. Answers the ID of its CoreAnimation context, or 0 where the platform has no remote layers.- u32 create_remote_layer(CompositorStateClient&, u64 remote_layer_id);+ // for. Answers how that view finds the layer, whose kind is None where the presentation has no remote layers.+ Compositing::RemoteLayerHostHandle create_remote_layer(CompositorStateClient&, u64 remote_layer_id);void destroy_remote_layer(u64 remote_layer_id);// The layer keeps the frame it shows until the context it is given next presents one.void show_context_in_remote_layer(u64 remote_layer_id, Optional<Web::CompositorContextId>);diff --git a/Services/Compositor/ConnectionFromClient.cpp b/Services/Compositor/ConnectionFromClient.cppindex f2877572b97..dc7a080fd08 100644--- a/Services/Compositor/ConnectionFromClient.cpp+++ b/Services/Compositor/ConnectionFromClient.cpp@@ -95,7 +95,7 @@ Messages::CompositorControlServer::CreateRemoteLayerResponse ConnectionFromClienauto connection = m_presentation_connections.get(presentation_id);if (!connection.has_value()) {dbgln("Compositor: Ignoring remote layer {} for presentation {}, which is already gone", remote_layer_id, presentation_id);- return 0u;+ return Compositing::RemoteLayerHostHandle {};}return m_compositor_state->create_remote_layer(**connection, remote_layer_id);}diff --git a/Services/Hub/HubClient.ipc b/Services/Hub/HubClient.ipcindex 48ebfa6b5b4..e58f98371e9 100644--- a/Services/Hub/HubClient.ipc+++ b/Services/Hub/HubClient.ipc@@ -326,8 +326,8 @@ endpoint HubClientview_keep_front_backing_store_as_backup(u64 view_id) =|view_clear_backup_backing_store(u64 view_id) =|view_clear_backing_stores(u64 view_id) =|- // The ID is 0 when the view has no remote layer, and the UI goes on showing backing stores.- view_set_remote_layer(u64 view_id, u32 core_animation_context_id) =|+ // The handle's kind is None when the view has no remote layer, and the UI goes on showing backing stores.+ view_set_remote_layer(u64 view_id, Compositing::RemoteLayerHostHandle host_handle) =|view_did_present_frame_in_remote_layer(u64 view_id, Gfx::IntSize size, double device_pixel_ratio) =|view_did_take_frame_snapshot(u64 view_id, u64 request_id, Optional<Gfx::ShareableBitmap> snapshot) =|view_did_hold_synchronized_resize_frame(u64 view_id, u64 token) =|diff --git a/Services/Hub/View.cpp b/Services/Hub/View.cppindex 03fbaa3e2ec..26a4a660469 100644--- a/Services/Hub/View.cpp+++ b/Services/Hub/View.cpp@@ -689,12 +689,12 @@ void View::did_accept_presented_backing_store(i32 bitmap_id, Gfx::IntRect damageui->async_view_accept_presented_backing_store(view_id(), bitmap_id, damage_rect);}-void View::did_create_remote_layer(u32 core_animation_context_id)+void View::did_create_remote_layer(Compositing::RemoteLayerHostHandle host_handle){- m_ui_hosts_remote_layer = core_animation_context_id != 0;+ m_ui_hosts_remote_layer = host_handle.kind != Compositing::RemoteLayerHostKind::None;m_ui_awaits_first_frame_in_remote_layer = m_ui_hosts_remote_layer;if (auto* ui = ConnectionFromUI::the())- ui->async_view_set_remote_layer(view_id(), core_animation_context_id);+ ui->async_view_set_remote_layer(view_id(), host_handle);}// The UI shows the backing stores it was given, as when a page from another process comes to display the tab, until itdiff --git a/Services/Hub/View.h b/Services/Hub/View.hindex 08e5b3d0f7b..8ed5c14de6a 100644--- a/Services/Hub/View.h+++ b/Services/Hub/View.h@@ -75,7 +75,7 @@ private:virtual void did_accept_presented_backing_store(i32 bitmap_id, Gfx::IntRect damage_rect) override;// NB: The UI hands a backing store back, once it no longer shows what is in it.virtual void release_backing_store(i32) override { }- virtual void did_create_remote_layer(u32 core_animation_context_id) override;+ virtual void did_create_remote_layer(Compositing::RemoteLayerHostHandle) override;virtual void did_present_frame_in_remote_layer(Gfx::IntSize, double device_pixel_ratio) override;virtual void did_hold_synchronized_resize_frame(u64 token) override;virtual void did_commit_synchronized_resize(u64 token) override;diff --git a/UI/Qt/HubConnection.cpp b/UI/Qt/HubConnection.cppindex b48bd8c20fa..2f0e3fd7f58 100644--- a/UI/Qt/HubConnection.cpp+++ b/UI/Qt/HubConnection.cpp@@ -148,10 +148,10 @@ void HubConnection::view_clear_backing_stores(u64 view_id)view->did_clear_backing_stores();}-void HubConnection::view_set_remote_layer(u64 view_id, u32 core_animation_context_id)+void HubConnection::view_set_remote_layer(u64 view_id, Compositing::RemoteLayerHostHandle host_handle){if (auto* view = RemoteView::find(view_id))- view->did_set_remote_layer(core_animation_context_id);+ view->did_set_remote_layer(host_handle);}void HubConnection::view_did_present_frame_in_remote_layer(u64 view_id, Gfx::IntSize size, double device_pixel_ratio)diff --git a/UI/Qt/HubConnection.h b/UI/Qt/HubConnection.hindex 6e05a688df3..e0d2f097a91 100644--- a/UI/Qt/HubConnection.h+++ b/UI/Qt/HubConnection.h@@ -170,7 +170,7 @@ private:virtual void view_keep_front_backing_store_as_backup(u64 view_id) override;virtual void view_clear_backup_backing_store(u64 view_id) override;virtual void view_clear_backing_stores(u64 view_id) override;- virtual void view_set_remote_layer(u64 view_id, u32 core_animation_context_id) override;+ virtual void view_set_remote_layer(u64 view_id, Compositing::RemoteLayerHostHandle host_handle) override;virtual void view_did_present_frame_in_remote_layer(u64 view_id, Gfx::IntSize size, double device_pixel_ratio) override;virtual void view_did_take_frame_snapshot(u64 view_id, u64 request_id, Optional<Gfx::ShareableBitmap> snapshot) override;// NB: A view waits for these while CoreAnimation commits a resize, and ignores those that come too late.diff --git a/UI/Qt/RemoteView.h b/UI/Qt/RemoteView.hindex 104e6d0ec4b..30e23fdea1e 100644--- a/UI/Qt/RemoteView.h+++ b/UI/Qt/RemoteView.h@@ -247,7 +247,7 @@ public:void did_keep_front_backing_store_as_backup() { m_backing_stores.keep_front_as_backup(); }void did_clear_backup_backing_store() { m_backing_stores.clear_backup(); }void did_clear_backing_stores() { m_backing_stores.clear(); }- void did_set_remote_layer(u32 core_animation_context_id) { remote_layer_changed(core_animation_context_id); }+ void did_set_remote_layer(Compositing::RemoteLayerHostHandle host_handle) { remote_layer_changed(host_handle); }void did_present_frame_in_remote_layer(Gfx::IntSize, double device_pixel_ratio);// Hands a backing store back to the page that presented it, which can have outlived the view.@@ -259,8 +259,8 @@ public:protected:virtual void show_context_menu(Menu&, Gfx::IntPoint) { }virtual void did_accept_presented_backing_store(i32, Gfx::IntRect) { }- // The ID is 0 when the view has no remote layer, and goes on showing backing stores.- virtual void remote_layer_changed(u32 core_animation_context_id) { (void)core_animation_context_id; }+ // The handle's kind is None when the view has no remote layer, and goes on showing backing stores.+ virtual void remote_layer_changed(Compositing::RemoteLayerHostHandle) { }virtual void release_backing_store(u64 page_id, i32 bitmap_id) { release_backing_store_to_page(page_id, bitmap_id); }void set_page_background_color_to_system_canvas(bool dark) { HubConnection::the().async_view_set_page_background_color_to_system_canvas(view_id(), dark); }diff --git a/UI/Qt/WebContentView.h b/UI/Qt/WebContentView.hindex 449680138b9..aaecae50dd7 100644--- a/UI/Qt/WebContentView.h+++ b/UI/Qt/WebContentView.h@@ -403,7 +403,7 @@ private:// The Compositor commits the page's frames into a remote layer, which this layer shows by the ID of its context.static bool can_host_remote_layers();- virtual void remote_layer_changed(u32 core_animation_context_id) override;+ virtual void remote_layer_changed(Compositing::RemoteLayerHostHandle) override;void update_remote_layer_host();void synchronize_resize_with_remote_layer();void await_resized_frame_before_commit(u64 token);diff --git a/UI/Qt/WebContentViewMac.mm b/UI/Qt/WebContentViewMac.mmindex 50169487592..52e16971917 100644--- a/UI/Qt/WebContentViewMac.mm+++ b/UI/Qt/WebContentViewMac.mm@@ -151,9 +151,9 @@ void WebContentView::release_resized_frame_with_commit(u64 token)}}-void WebContentView::remote_layer_changed(u32 core_animation_context_id)+void WebContentView::remote_layer_changed(Compositing::RemoteLayerHostHandle host_handle){- m_remote_layer_context_id = core_animation_context_id;+ m_remote_layer_context_id = host_handle.kind == Compositing::RemoteLayerHostKind::CoreAnimationContext ? static_cast<u32>(host_handle.id) : 0;update_remote_layer_host();schedule_repaint();}