Skip to content

Truly independent web browser

LibWeb: Only count a video sink as registered once a Compositor has it

Zaggy102466aace1de81d
diff --git a/Libraries/LibWeb/Compositor/CompositorHost.cpp b/Libraries/LibWeb/Compositor/CompositorHost.cpp
index f6661c480fa..f79ca211ea4 100644
--- a/Libraries/LibWeb/Compositor/CompositorHost.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorHost.cpp
@@ -485,10 +485,13 @@ void CompositorHost::register_animated_images_with_new_compositor()
}
}
-void CompositorHost::add_video_sink(Media::VideoSinkHandle video_sink_handle, NonnullRefPtr<Compositing::VideoFramePresentationPage> presentation_page)
+bool CompositorHost::add_video_sink(Media::VideoSinkHandle video_sink_handle, NonnullRefPtr<Compositing::VideoFramePresentationPage> presentation_page)
{
- if (auto* connection = compositor_connection())
- connection->add_video_sink(video_sink_handle, move(presentation_page));
+ auto* connection = compositor_connection();
+ if (!connection)
+ return false;
+ connection->add_video_sink(video_sink_handle, move(presentation_page));
+ return true;
}
void CompositorHost::remove_video_sink(Media::VideoSinkHandle video_sink_handle)
diff --git a/Libraries/LibWeb/Compositor/CompositorHost.h b/Libraries/LibWeb/Compositor/CompositorHost.h
index 835dea53ef2..fbb22fd5b32 100644
--- a/Libraries/LibWeb/Compositor/CompositorHost.h
+++ b/Libraries/LibWeb/Compositor/CompositorHost.h
@@ -154,7 +154,8 @@ public:
// A new compositor process has heard of none of the images.
void register_animated_images_with_new_compositor();
- void add_video_sink(Media::VideoSinkHandle, NonnullRefPtr<Compositing::VideoFramePresentationPage>);
+ // Returns whether a compositor heard of the sink, which one that connects later will not have.
+ [[nodiscard]] bool add_video_sink(Media::VideoSinkHandle, NonnullRefPtr<Compositing::VideoFramePresentationPage>);
void remove_video_sink(Media::VideoSinkHandle);
void set_video_sink_ticking(Media::VideoSinkHandle, bool should_tick);
Compositing::VideoFrameHold::ReleaseThroughCompositor video_frame_hold_releaser_for_current_connection() const;
diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
index 2242b2698f6..aec1a4a2fc4 100644
--- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
@@ -98,10 +98,13 @@ public:
if (m_compositor_host == &compositor_host)
return;
unregister();
+ auto presentation_page = MUST(Compositing::VideoFramePresentationPage::create());
+ // Without a compositor to hear of it, the sink is registered when one connects.
+ if (!compositor_host.add_video_sink(m_handle, presentation_page))
+ return;
m_compositor_host = &compositor_host;
m_frame_counts_of_earlier_pages += exchange(m_frame_counts_of_this_page, {});
- m_presentation_page = MUST(Compositing::VideoFramePresentationPage::create());
- m_compositor_host->add_video_sink(m_handle, *m_presentation_page);
+ m_presentation_page = move(presentation_page);
}
void unregister()