Skip to content

Truly independent web browser

LibCompositing+LibWeb+Compositor: Draw video sinks by their handle

Aliaksandr Kalenik570bd0aa7877
diff --git a/Libraries/LibCompositing/DisplayList/DisplayListResourceIds.h b/Libraries/LibCompositing/DisplayList/DisplayListResourceIds.h
index 6e38dc7cd02..c9c4f3531c7 100644
--- a/Libraries/LibCompositing/DisplayList/DisplayListResourceIds.h
+++ b/Libraries/LibCompositing/DisplayList/DisplayListResourceIds.h
@@ -6,7 +6,6 @@
#pragma once
-#include <AK/Atomic.h>
#include <AK/DistinctNumeric.h>
#include <AK/Types.h>
@@ -14,16 +13,9 @@ namespace Compositing {
AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, FontResourceId);
AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, ImageFrameResourceId);
-AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, VideoSinkResourceId);
AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, DisplayListResourceId);
AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, CanvasId);
// Names the connection whose canvases a surface belongs to. Never reused, unlike connection IDs.
AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, CanvasSurfaceOwnerId);
-inline VideoSinkResourceId allocate_video_sink_resource_id()
-{
- static Atomic<u64> s_next_id { 1 };
- return VideoSinkResourceId { s_next_id.fetch_add(1, AK::MemoryOrder::memory_order_relaxed) };
-}
-
}
diff --git a/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.cpp b/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.cpp
index 8d0f5192186..fed9d4e54d9 100644
--- a/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.cpp
+++ b/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.cpp
@@ -10,7 +10,6 @@
#include <LibCompositing/RustFFI.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Font/Font.h>
-#include <LibMediaCodecs/VideoFrame.h>
namespace Compositing {
@@ -28,17 +27,10 @@ struct DisplayListStoredImageFrameResource {
mutable Optional<bool> force_dark_should_filter;
};
-struct DisplayListStoredVideoSinkResource {
- AK_ALLOC_WITH_KMALLOC;
-
- RefPtr<Media::DisplayingVideoSink> sink;
-};
-
bool DisplayListResourceSet::is_empty() const
{
return fonts.is_empty()
&& image_frames.is_empty()
- && video_sinks.is_empty()
&& display_lists.is_empty();
}
@@ -48,8 +40,6 @@ void DisplayListResourceSet::include(DisplayListResourceSet const& other)
fonts.set(id, AK::HashSetExistingEntryBehavior::Keep);
for (auto id : other.image_frames)
image_frames.set(id, AK::HashSetExistingEntryBehavior::Keep);
- for (auto id : other.video_sinks)
- video_sinks.set(id, AK::HashSetExistingEntryBehavior::Keep);
for (auto id : other.display_lists)
display_lists.set(id, AK::HashSetExistingEntryBehavior::Keep);
}
@@ -123,13 +113,6 @@ ImageFrameResourceId DisplayListResourceStorage::add_image_frame(Gfx::DecodedIma
return { id };
}
-VideoSinkResourceId DisplayListResourceStorage::add_video_sink(VideoSinkResourceId id, Media::VideoSinkHandle sink_handle)
-{
- m_has_resources_added_since_last_retain = true;
- m_video_sink_handles.set(id.value(), sink_handle, AK::HashSetExistingEntryBehavior::Keep);
- return id;
-}
-
void DisplayListResourceStorage::set_font(FontResourceId id, NonnullRefPtr<Gfx::Font const> font)
{
m_has_resources_added_since_last_retain = true;
@@ -171,12 +154,6 @@ DisplayListResourceTransaction DisplayListResourceStorage::create_transaction(
if (!previous.image_frames.contains(id))
transaction.image_frames.append({ id, image_frame(id) });
}
- for (auto id : current.video_sinks) {
- if (previous.video_sinks.contains(id))
- continue;
- if (auto sink_handle = video_sink_handle(id); sink_handle.has_value())
- transaction.video_sinks.append({ id, *sink_handle });
- }
for (auto id : previous.fonts) {
if (!current.fonts.contains(id))
@@ -186,10 +163,6 @@ DisplayListResourceTransaction DisplayListResourceStorage::create_transaction(
if (!current.image_frames.contains(id))
transaction.image_frame_ids_to_remove.append(id);
}
- for (auto id : previous.video_sinks) {
- if (!current.video_sinks.contains(id))
- transaction.video_sink_ids_to_remove.append(id);
- }
for (auto id : previous.display_lists) {
if (!current.display_lists.contains(id))
transaction.display_list_ids_to_remove.append(id);
@@ -208,8 +181,6 @@ DisplayListResourceSet DisplayListResourceStorage::apply_transaction(DisplayList
removed_resources.image_frames.set(frame.id);
set_image_frame(frame.id, move(frame.frame));
}
- for (auto& video_sink : transaction.video_sinks)
- add_video_sink(video_sink.id, video_sink.sink_handle);
for (auto id : transaction.font_ids_to_remove) {
if (m_fonts.remove(id.value()))
@@ -220,12 +191,6 @@ DisplayListResourceSet DisplayListResourceStorage::apply_transaction(DisplayList
if (m_image_frames.remove(id.value()))
removed_resources.image_frames.set(id);
}
- for (auto id : transaction.video_sink_ids_to_remove) {
- auto removed_handle = m_video_sink_handles.remove(id.value());
- auto removed_sink = m_video_sinks.remove(id.value());
- if (removed_handle || removed_sink)
- removed_resources.video_sinks.set(id);
- }
return removed_resources;
}
@@ -245,30 +210,8 @@ DisplayListResourceSet DisplayListResourceStorage::retain_only(DisplayListResour
removed_resources.image_frames.set(ImageFrameResourceId { id });
return true;
});
- auto remove_video_resource = [&](auto id) {
- if (resource_set.video_sinks.contains(VideoSinkResourceId { id }))
- return false;
- removed_resources.video_sinks.set(VideoSinkResourceId { id });
- return true;
- };
- m_video_sink_handles.remove_all_matching([&](auto id, auto const&) { return remove_video_resource(id); });
- m_video_sinks.remove_all_matching([&](auto id, auto const&) { return remove_video_resource(id); });
m_has_resources_added_since_last_retain = false;
return removed_resources;
}
-void DisplayListResourceStorage::set_video_sink(VideoSinkResourceId id, RefPtr<Media::DisplayingVideoSink> sink)
-{
- m_has_resources_added_since_last_retain = true;
- m_video_sinks.ensure(id.value(), [] { return make<DisplayListStoredVideoSinkResource>(); })->sink = move(sink);
-}
-
-RefPtr<Media::DisplayingVideoSink const> DisplayListResourceStorage::video_sink(VideoSinkResourceId id) const
-{
- auto stored = m_video_sinks.find(id.value());
- if (stored == m_video_sinks.end())
- return nullptr;
- return stored->value->sink;
-}
-
}
diff --git a/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.h b/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.h
index e559407fe6d..c02f5d66ec6 100644
--- a/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.h
+++ b/Libraries/LibCompositing/DisplayList/DisplayListResourceStorage.h
@@ -26,9 +26,6 @@
#include <LibGfx/Font/Font.h>
#include <LibGfx/Forward.h>
#include <LibIPC/Forward.h>
-#include <LibMedia/Sinks/DisplayingVideoSink.h>
-#include <LibMedia/VideoSinkHandle.h>
-#include <LibMediaCodecs/VideoFrame.h>
namespace Compositing {
@@ -38,7 +35,6 @@ struct COMPOSITING_API DisplayListResourceSet {
HashTable<FontResourceId> fonts;
HashTable<ImageFrameResourceId> image_frames;
- HashTable<VideoSinkResourceId> video_sinks;
HashTable<DisplayListResourceId> display_lists;
};
@@ -52,13 +48,6 @@ struct DisplayListImageFrameResource {
Gfx::DecodedImageFrame frame;
};
-struct DisplayListVideoSinkResource {
- VideoSinkResourceId id;
- // The display list routes a video by sink handle; the compositor resolves it to the hosted sink at
- // transaction-apply, and the draw reads the sink's current frame.
- Media::VideoSinkHandle sink_handle;
-};
-
// The -webkit-font-smoothing values the recorder writes as a byte, in the order the CSS enum declares them.
enum class FontSmoothing : u8 {
Auto,
@@ -68,17 +57,14 @@ enum class FontSmoothing : u8 {
};
struct DisplayListStoredImageFrameResource;
-struct DisplayListStoredVideoSinkResource;
// A display list recorded in this process, which goes with the visual context tree it was recorded against.
struct DisplayListResourceTransaction {
Vector<DisplayListFontResource> fonts;
Vector<DisplayListImageFrameResource> image_frames;
- Vector<DisplayListVideoSinkResource> video_sinks;
Vector<FontResourceId> font_ids_to_remove;
Vector<ImageFrameResourceId> image_frame_ids_to_remove;
- Vector<VideoSinkResourceId> video_sink_ids_to_remove;
Vector<DisplayListResourceId> display_list_ids_to_remove;
};
@@ -93,7 +79,6 @@ public:
FontResourceId add_font(Gfx::Font const&);
ImageFrameResourceId add_image_frame(Gfx::DecodedImageFrame const&);
- VideoSinkResourceId add_video_sink(VideoSinkResourceId, Media::VideoSinkHandle);
void set_font(FontResourceId, NonnullRefPtr<Gfx::Font const>);
// Returns the resources that the transaction removed or replaced, so whatever was made from them can be dropped.
DisplayListResourceSet apply_transaction(DisplayListResourceTransaction&&);
@@ -106,7 +91,6 @@ public:
// Returns the resources that were removed.
DisplayListResourceSet retain_only(DisplayListResourceSet const&);
bool has_resources_added_since_last_retain() const { return m_has_resources_added_since_last_retain; }
- void set_video_sink(VideoSinkResourceId, RefPtr<Media::DisplayingVideoSink>);
// Shows other pixels under an id the display lists keep drawing, as an animated image moves to its next frame.
void replace_image_frame_pixels(ImageFrameResourceId, Gfx::DecodedImageFrame);
// A stamp for each image frame that has had its pixels replaced. No two replacements share a stamp, even across the
@@ -119,9 +103,6 @@ public:
Gfx::DecodedImageFrame const& image_frame(ImageFrameResourceId) const;
// Whether force-dark should invert this image, worked out once and cached.
bool image_frame_should_force_dark(ImageFrameResourceId) const;
- RefPtr<Media::DisplayingVideoSink const> video_sink(VideoSinkResourceId id) const;
- Optional<Media::VideoSinkHandle> video_sink_handle(VideoSinkResourceId id) const { return m_video_sink_handles.get(id.value()); }
- HashMap<u64, Media::VideoSinkHandle> const& video_sink_handles() const { return m_video_sink_handles; }
private:
void set_image_frame(ImageFrameResourceId, Gfx::DecodedImageFrame);
@@ -131,8 +112,6 @@ private:
HashMap<u64, NonnullOwnPtr<DisplayListStoredImageFrameResource>> m_image_frames;
HashMap<u64, u64> m_image_frame_pixel_generations;
u64 m_next_image_frame_pixel_generation { 1 };
- HashMap<u64, Media::VideoSinkHandle> m_video_sink_handles;
- HashMap<u64, NonnullOwnPtr<DisplayListStoredVideoSinkResource>> m_video_sinks;
};
}
@@ -149,11 +128,6 @@ COMPOSITING_API ErrorOr<void> encode(Encoder&, Compositing::DisplayListImageFram
template<>
COMPOSITING_API ErrorOr<Compositing::DisplayListImageFrameResource> decode(Decoder&);
-template<>
-COMPOSITING_API ErrorOr<void> encode(Encoder&, Compositing::DisplayListVideoSinkResource const&);
-template<>
-COMPOSITING_API ErrorOr<Compositing::DisplayListVideoSinkResource> decode(Decoder&);
-
template<>
COMPOSITING_API ErrorOr<void> encode(Encoder&, Compositing::DisplayListResourceTransaction const&);
template<>
diff --git a/Libraries/LibCompositing/DisplayList/DisplayListResourceTransaction.cpp b/Libraries/LibCompositing/DisplayList/DisplayListResourceTransaction.cpp
index 1a02ec7714e..e2e459a4a46 100644
--- a/Libraries/LibCompositing/DisplayList/DisplayListResourceTransaction.cpp
+++ b/Libraries/LibCompositing/DisplayList/DisplayListResourceTransaction.cpp
@@ -70,33 +70,15 @@ ErrorOr<Compositing::DisplayListImageFrameResource> decode(Decoder& decoder)
};
}
-template<>
-ErrorOr<void> encode(Encoder& encoder, Compositing::DisplayListVideoSinkResource const& resource)
-{
- TRY(encoder.encode(resource.id));
- TRY(encoder.encode(resource.sink_handle));
- return {};
-}
-
-template<>
-ErrorOr<Compositing::DisplayListVideoSinkResource> decode(Decoder& decoder)
-{
- auto id = TRY(decoder.decode<Compositing::VideoSinkResourceId>());
- auto sink_handle = TRY(decoder.decode<Media::VideoSinkHandle>());
- return Compositing::DisplayListVideoSinkResource { .id = id, .sink_handle = sink_handle };
-}
-
template<>
ErrorOr<void> encode(Encoder& encoder, Compositing::DisplayListResourceTransaction const& transaction)
{
TRY(encoder.encode(transaction.fonts));
TRY(encoder.encode(transaction.image_frames));
- TRY(encoder.encode(transaction.video_sinks));
// Only Rust sends nested display lists, which only the compositor's Rust receives.
TRY(encoder.encode_size(0));
TRY(encoder.encode(transaction.font_ids_to_remove));
TRY(encoder.encode(transaction.image_frame_ids_to_remove));
- TRY(encoder.encode(transaction.video_sink_ids_to_remove));
TRY(encoder.encode(transaction.display_list_ids_to_remove));
return {};
}
@@ -106,7 +88,6 @@ ErrorOr<Compositing::DisplayListResourceTransaction> decode(Decoder& decoder)
{
auto fonts = TRY(decoder.decode<Vector<Compositing::DisplayListFontResource>>());
auto image_frames = TRY(decoder.decode<Vector<Compositing::DisplayListImageFrameResource>>());
- auto video_sinks = TRY(decoder.decode<Vector<Compositing::DisplayListVideoSinkResource>>());
// Only the compositor's Rust receives nested display lists, with the visual context trees they were recorded
// against.
@@ -116,10 +97,8 @@ ErrorOr<Compositing::DisplayListResourceTransaction> decode(Decoder& decoder)
return Compositing::DisplayListResourceTransaction {
.fonts = move(fonts),
.image_frames = move(image_frames),
- .video_sinks = move(video_sinks),
.font_ids_to_remove = TRY(decoder.decode<Vector<Compositing::FontResourceId>>()),
.image_frame_ids_to_remove = TRY(decoder.decode<Vector<Compositing::ImageFrameResourceId>>()),
- .video_sink_ids_to_remove = TRY(decoder.decode<Vector<Compositing::VideoSinkResourceId>>()),
.display_list_ids_to_remove = TRY(decoder.decode<Vector<Compositing::DisplayListResourceId>>()),
};
}
diff --git a/Libraries/LibCompositing/DisplayList/RustFFIAssertions.cpp b/Libraries/LibCompositing/DisplayList/RustFFIAssertions.cpp
index 76986d6a1ef..db667fedb96 100644
--- a/Libraries/LibCompositing/DisplayList/RustFFIAssertions.cpp
+++ b/Libraries/LibCompositing/DisplayList/RustFFIAssertions.cpp
@@ -24,6 +24,7 @@
#include <LibGfx/ScalingMode.h>
#include <LibGfx/Size.h>
#include <LibGfx/WindingRule.h>
+#include <LibMedia/VideoSinkHandle.h>
// The Rust side mirrors these LibGfx value types field for field; the checks keep the two in step.
@@ -166,7 +167,7 @@ static_assert(to_underlying(Compositing::RustFFI::ColorFilterType::Saturate) ==
static_assert(to_underlying(Compositing::RustFFI::ColorFilterType::Sepia) == to_underlying(Gfx::ColorFilterType::Sepia));
static_assert(sizeof(Compositing::RustFFI::FontResourceId) == sizeof(FontResourceId));
static_assert(sizeof(Compositing::RustFFI::ImageFrameResourceId) == sizeof(ImageFrameResourceId));
-static_assert(sizeof(Compositing::RustFFI::VideoSinkResourceId) == sizeof(VideoSinkResourceId));
+static_assert(sizeof(Compositing::RustFFI::VideoSinkHandle) == sizeof(Media::VideoSinkHandle));
static_assert(sizeof(Compositing::RustFFI::DisplayListResourceId) == sizeof(DisplayListResourceId));
static_assert(sizeof(Compositing::RustFFI::CanvasId) == sizeof(CanvasId));
static_assert(sizeof(Compositing::RustFFI::CompositorContextId) == sizeof(Web::CompositorContextId));
diff --git a/Libraries/LibCompositing/Rust/build.rs b/Libraries/LibCompositing/Rust/build.rs
index 8124c2df0e7..916a72ee799 100644
--- a/Libraries/LibCompositing/Rust/build.rs
+++ b/Libraries/LibCompositing/Rust/build.rs
@@ -104,7 +104,7 @@ fn expose_shared_abi_types_as_cpp_types(config: &mut cbindgen::Config) {
"ReplayLayer",
"ReplayMask",
"CanvasId",
- "VideoSinkResourceId",
+ "VideoSinkHandle",
"Canvas2DPaintKind",
"Canvas2DPatternRepetition",
"PathGeometryData",
@@ -158,7 +158,7 @@ fn expose_shared_abi_types_as_cpp_types(config: &mut cbindgen::Config) {
("ReplayLayer", "Compositing::ReplayLayer"),
("ReplayMask", "Compositing::ReplayMask"),
("CanvasId", "Compositing::CanvasId"),
- ("VideoSinkResourceId", "Compositing::VideoSinkResourceId"),
+ ("VideoSinkHandle", "Media::VideoSinkHandle"),
("Canvas2DPaintKind", "Compositing::Canvas2DPaintKind"),
("Canvas2DPatternRepetition", "Compositing::Canvas2DPatternRepetition"),
("CapStyle", "Gfx::CapStyle"),
@@ -471,7 +471,7 @@ fn main() -> Result<(), Box<dyn Error>> {
"OptionalAffineTransform",
"FontResourceId",
"ImageFrameResourceId",
- "VideoSinkResourceId",
+ "VideoSinkHandle",
"DisplayListResourceId",
"CanvasId",
"CompositorContextId",
@@ -492,7 +492,7 @@ fn main() -> Result<(), Box<dyn Error>> {
"ContextRef",
"FontResourceId",
"ImageFrameResourceId",
- "VideoSinkResourceId",
+ "VideoSinkHandle",
"DisplayListResourceId",
"CanvasId",
"CompositorContextId",
@@ -556,6 +556,7 @@ fn main() -> Result<(), Box<dyn Error>> {
("OptionalAffineTransform", "Optional<Gfx::AffineTransform>"),
("CompositorContextId", "Web::CompositorContextId"),
("UniqueNodeId", "Web::UniqueNodeID"),
+ ("VideoSinkHandle", "Media::VideoSinkHandle"),
];
for (rust_name, cpp_name) in references_renamed_to_real_types {
commands_config
@@ -586,6 +587,7 @@ fn main() -> Result<(), Box<dyn Error>> {
"LibCompositing/DisplayList/ContextRef.h",
"LibCompositing/DisplayList/DisplayListResourceIds.h",
"LibCompositing/Forward.h",
+ "LibMedia/VideoSinkHandle.h",
"LibWebCommon/PixelUnits.h",
"LibCompositing/Types.h",
]
diff --git a/Libraries/LibCompositing/Rust/src/display_list/commands.rs b/Libraries/LibCompositing/Rust/src/display_list/commands.rs
index 1bc87a92cf1..b505cd57c16 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/commands.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/commands.rs
@@ -302,9 +302,9 @@ impl FfiBytes for ImageFrameResourceId {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(transparent)]
-pub struct VideoSinkResourceId(pub u64);
+pub struct VideoSinkHandle(pub u64);
-impl FfiBytes for VideoSinkResourceId {
+impl FfiBytes for VideoSinkHandle {
#[inline]
fn write_ffi_bytes(&self, out: &mut [u8]) {
self.0.write_ffi_bytes(out);
@@ -939,12 +939,12 @@ impl DisplayListCommand for DrawCanvas {
#[repr(C)]
pub struct DrawVideoFrame {
pub dst_rect: IntRect,
- pub video_sink_id: VideoSinkResourceId,
+ pub video_sink_handle: VideoSinkHandle,
pub scaling_mode: ScalingMode,
}
ffi_bytes_fields!(DrawVideoFrame {
dst_rect,
- video_sink_id,
+ video_sink_handle,
scaling_mode
});
diff --git a/Libraries/LibCompositing/Rust/src/display_list/damage.rs b/Libraries/LibCompositing/Rust/src/display_list/damage.rs
index aa41ed1dc0f..d5f32e91742 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/damage.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/damage.rs
@@ -18,7 +18,7 @@ use crate::display_list::commands::{
DisplayListCommandRun, DisplayListCommandType, DisplayListDataSpan, DisplayListInlineClip,
DisplayListPaintStyleType, DrawGlyphRun, DrawScaledDecodedImageFrame, EffectNodeIndex, FillPath, FillRect,
INLINE_CLIP_ENTRY_SIZE, ImageFrameResourceId, OptionalColor, OptionalFloatRect, PaintScrollBar, PaintTextShadow,
- PathPaintKind, SpatialNodeIndex, StrokePath, VISUAL_VIEWPORT_NODE_INDEX, VideoSinkResourceId,
+ PathPaintKind, SpatialNodeIndex, StrokePath, VISUAL_VIEWPORT_NODE_INDEX, VideoSinkHandle,
};
use crate::fast_hash::FastMap;
use crate::host::FfiAnimatedContentViewportEffect;
@@ -1551,7 +1551,7 @@ pub struct DisplayListFrame<'a> {
#[derive(Clone, Copy, Default)]
pub struct LiveContentChanges<'a> {
pub canvases: &'a [CanvasId],
- pub video_sinks: &'a [VideoSinkResourceId],
+ pub video_sinks: &'a [VideoSinkHandle],
pub image_frames: &'a [ImageFrameResourceId],
/// What the compositor repaints whatever the lists hold, such as a blinking caret.
pub forced_damage_rect: IntRect,
@@ -1582,7 +1582,7 @@ impl LiveContentChanges<'_> {
fn includes(&self, content: LiveContent) -> bool {
match content {
LiveContent::Canvas(canvas_id) => self.canvases.contains(&canvas_id),
- LiveContent::VideoFrame(video_sink_id) => self.video_sinks.contains(&video_sink_id),
+ LiveContent::VideoFrame(video_sink_handle) => self.video_sinks.contains(&video_sink_handle),
LiveContent::ImageFrame(image_frame_id) => self.image_frames.contains(&image_frame_id),
}
}
@@ -2243,14 +2243,14 @@ mod tests {
let video = command_bytes(
&DrawVideoFrame {
dst_rect: rect,
- video_sink_id: VideoSinkResourceId(1),
+ video_sink_handle: VideoSinkHandle(1),
scaling_mode: ScalingMode::NearestNeighbor,
},
Some(rect),
ContextRef::default(),
);
let changed_video = LiveContentChanges {
- video_sinks: &[VideoSinkResourceId(1)],
+ video_sinks: &[VideoSinkHandle(1)],
..LiveContentChanges::default()
};
assert_eq!(
diff --git a/Libraries/LibCompositing/Rust/src/display_list/summary.rs b/Libraries/LibCompositing/Rust/src/display_list/summary.rs
index 1120be270a7..a586bd29220 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/summary.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/summary.rs
@@ -26,7 +26,7 @@ pub struct IndexedRecord {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum LiveContent {
Canvas(CanvasId),
- VideoFrame(VideoSinkResourceId),
+ VideoFrame(VideoSinkHandle),
ImageFrame(ImageFrameResourceId),
}
@@ -41,7 +41,7 @@ pub struct LiveContentRecord {
pub struct DisplayListSummary {
pub font_ids: Vec<u64>,
pub image_frame_ids: Vec<u64>,
- pub video_sink_ids: Vec<u64>,
+ pub video_sink_handles: Vec<u64>,
pub display_list_ids: Vec<u64>,
pub canvas_ids: Vec<u64>,
pub carets: Vec<IndexedRecord>,
@@ -64,7 +64,7 @@ fn live_content_of(command_type: DisplayListCommandType, payload: &[u8]) -> Opti
match command_type {
T::DrawCanvas => Some(LiveContent::Canvas(read_command::<DrawCanvas>(payload).canvas_id)),
T::DrawVideoFrame => Some(LiveContent::VideoFrame(
- read_command::<DrawVideoFrame>(payload).video_sink_id,
+ read_command::<DrawVideoFrame>(payload).video_sink_handle,
)),
T::DrawScaledDecodedImageFrame => Some(LiveContent::ImageFrame(
read_command::<DrawScaledDecodedImageFrame>(payload).frame_id,
@@ -102,7 +102,7 @@ fn note_referenced_ids(command_type: DisplayListCommandType, payload: &[u8], ids
}
T::DrawVideoFrame => {
ids.video_sinks
- .insert(read_command::<DrawVideoFrame>(payload).video_sink_id.0);
+ .insert(read_command::<DrawVideoFrame>(payload).video_sink_handle.0);
}
T::DrawCanvas => {
ids.canvases.insert(read_command::<DrawCanvas>(payload).canvas_id.0);
@@ -223,7 +223,7 @@ pub fn summarize(tape: &[u8], command_runs: &[DisplayListCommandRun]) -> Display
}
summary.font_ids = sorted(ids.fonts);
summary.image_frame_ids = sorted(ids.image_frames);
- summary.video_sink_ids = sorted(ids.video_sinks);
+ summary.video_sink_handles = sorted(ids.video_sinks);
summary.display_list_ids = sorted(ids.display_lists);
summary.canvas_ids = sorted(ids.canvases);
summary
diff --git a/Libraries/LibCompositing/Rust/src/ipc_types.rs b/Libraries/LibCompositing/Rust/src/ipc_types.rs
index 67fb5be50d0..a84cdfd8d04 100644
--- a/Libraries/LibCompositing/Rust/src/ipc_types.rs
+++ b/Libraries/LibCompositing/Rust/src/ipc_types.rs
@@ -222,12 +222,9 @@ impl std::fmt::Debug for NestedDisplayListResource {
/// image frames: those go ahead of it, in messages that the C++ of the compositor takes.
#[derive(Clone, Debug, Default)]
pub struct Compositing_DisplayListResourceTransaction {
- // The resource ID of each video sink, and the handle of the sink.
- pub video_sinks: Vec<(u64, u64)>,
pub display_lists: Vec<NestedDisplayListResource>,
pub font_ids_to_remove: Vec<u64>,
pub image_frame_ids_to_remove: Vec<u64>,
- pub video_sink_ids_to_remove: Vec<u64>,
pub display_list_ids_to_remove: Vec<u64>,
}
@@ -235,7 +232,6 @@ impl Compositing_DisplayListResourceTransaction {
pub fn removes_anything(&self) -> bool {
!self.font_ids_to_remove.is_empty()
|| !self.image_frame_ids_to_remove.is_empty()
- || !self.video_sink_ids_to_remove.is_empty()
|| !self.display_list_ids_to_remove.is_empty()
}
}
@@ -245,18 +241,12 @@ impl Encode for Compositing_DisplayListResourceTransaction {
// No fonts, and no image frames.
encoder.encode_size(0)?;
encoder.encode_size(0)?;
- encoder.encode_size(self.video_sinks.len())?;
- for (id, handle) in &self.video_sinks {
- encoder.encode(id)?;
- encoder.encode(handle)?;
- }
encoder.encode_size(self.display_lists.len())?;
for display_list in &self.display_lists {
display_list.encode_into(encoder)?;
}
encoder.encode(&self.font_ids_to_remove)?;
encoder.encode(&self.image_frame_ids_to_remove)?;
- encoder.encode(&self.video_sink_ids_to_remove)?;
encoder.encode(&self.display_list_ids_to_remove)
}
}
@@ -270,11 +260,6 @@ impl Decode for Compositing_DisplayListResourceTransaction {
"a display list's fonts and image frames go ahead of it",
));
}
- let video_sink_count = decoder.decode_size()?;
- let mut video_sinks = Vec::new();
- for _ in 0..video_sink_count {
- video_sinks.push((decoder.decode()?, decoder.decode()?));
- }
let display_list_count = decoder.decode_size()?;
let mut display_lists = Vec::new();
for _ in 0..display_list_count {
@@ -303,11 +288,9 @@ impl Decode for Compositing_DisplayListResourceTransaction {
});
}
Ok(Self {
- video_sinks,
display_lists,
font_ids_to_remove: decoder.decode()?,
image_frame_ids_to_remove: decoder.decode()?,
- video_sink_ids_to_remove: decoder.decode()?,
display_list_ids_to_remove: decoder.decode()?,
})
}
diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.cpp b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
index d2175498e4a..f4b86d0ea70 100644
--- a/Libraries/LibWeb/Compositor/CompositorConnection.cpp
+++ b/Libraries/LibWeb/Compositor/CompositorConnection.cpp
@@ -938,7 +938,7 @@ extern "C" WEB_API bool web_compositor_create_shared_buffer(size_t size, Web::Co
extern "C" WEB_API void web_compositor_shared_buffer_release(void* owner);
extern "C" WEB_API bool web_compositor_post_screenshot_request(void* poster, void* request);
extern "C" WEB_API void web_screenshot_request_destroy(void* request);
-extern "C" WEB_API bool web_compositor_stage_rasterization(void* poster, u64 token, void const* const* fonts, size_t font_count, void const* const* image_frames, size_t image_frame_count, u64 const* video_sinks, size_t video_sink_count, void const* target_bitmap);
+extern "C" WEB_API bool web_compositor_stage_rasterization(void* poster, u64 token, void const* const* fonts, size_t font_count, void const* const* image_frames, size_t image_frame_count, void const* target_bitmap);
extern "C" WEB_API bool web_compositor_post_fonts_and_image_frames(void* poster, u64 context_id, void const* const* fonts, size_t font_count, void const* const* image_frames, size_t image_frame_count)
{
@@ -985,7 +985,7 @@ extern "C" WEB_API void web_screenshot_request_destroy(void* request)
delete static_cast<Web::Compositor::ScreenshotRequestForPaintThread*>(request);
}
-extern "C" WEB_API bool web_compositor_stage_rasterization(void* poster, u64 token, void const* const* fonts, size_t font_count, void const* const* image_frames, size_t image_frame_count, u64 const* video_sinks, size_t video_sink_count, void const* target_bitmap)
+extern "C" WEB_API bool web_compositor_stage_rasterization(void* poster, u64 token, void const* const* fonts, size_t font_count, void const* const* image_frames, size_t image_frame_count, void const* target_bitmap)
{
Compositing::DisplayListResourceTransaction staged_resources;
for (size_t i = 0; i < font_count; ++i) {
@@ -996,8 +996,6 @@ extern "C" WEB_API bool web_compositor_stage_rasterization(void* poster, u64 tok
auto const& frame = *static_cast<Gfx::DecodedImageFrame const*>(image_frames[i]);
staged_resources.image_frames.append({ Compositing::ImageFrameResourceId { frame.id() }, frame });
}
- for (size_t i = 0; i < video_sink_count; ++i)
- staged_resources.video_sinks.append({ Compositing::VideoSinkResourceId { video_sinks[2 * i] }, Media::VideoSinkHandle { video_sinks[2 * i + 1] } });
auto& target = const_cast<Gfx::Bitmap&>(*static_cast<Gfx::Bitmap const*>(target_bitmap));
auto encoded_message = MUST(Messages::CompositorWebContentServer::StageRasterization::static_encode(token, staged_resources, Gfx::ShareableBitmap { target, Gfx::ShareableBitmap::ConstructWithKnownGoodBitmap }));
return static_cast<IPC::ThreadSafeMessagePoster*>(poster)->try_post(encoded_message);
diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
index aec1a4a2fc4..67bc45630ac 100644
--- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
@@ -79,9 +79,8 @@ class HTMLMediaElement::ActiveVideoSink {
public:
AK_ALLOC_WITH_KMALLOC;
- ActiveVideoSink(Media::VideoSinkHandle handle, Compositing::VideoSinkResourceId resource_id)
+ explicit ActiveVideoSink(Media::VideoSinkHandle handle)
: m_handle(handle)
- , m_resource_id(resource_id)
{
}
@@ -91,7 +90,6 @@ public:
}
Media::VideoSinkHandle handle() const { return m_handle; }
- Compositing::VideoSinkResourceId resource_id() const { return m_resource_id; }
void register_with(Compositor::CompositorHost& compositor_host)
{
@@ -174,7 +172,6 @@ public:
private:
Media::VideoSinkHandle m_handle;
- Compositing::VideoSinkResourceId m_resource_id;
Compositor::CompositorHost* m_compositor_host { nullptr };
RefPtr<Compositing::VideoFramePresentationPage> m_presentation_page;
WeakPtr<Compositing::VideoFrameHold> m_latest_hold;
@@ -2090,13 +2087,6 @@ Optional<Media::VideoSinkHandle> HTMLMediaElement::video_sink_handle() const
return m_active_video_sink->handle();
}
-Optional<Compositing::VideoSinkResourceId> HTMLMediaElement::video_sink_resource_id() const
-{
- if (!m_active_video_sink)
- return {};
- return m_active_video_sink->resource_id();
-}
-
// https://html.spec.whatwg.org/multipage/media.html#media-data
bool HTMLMediaElement::media_data_is_cors_cross_origin() const
{
@@ -2145,7 +2135,7 @@ void HTMLMediaElement::attach_selected_video_track_sink(Media::Track const& trac
if (auto* video_element = as_if<HTMLVideoElement>(&self))
video_element->set_intrinsic_video_dimensions(size);
}));
- m_active_video_sink = make<ActiveVideoSink>(handle, Compositing::allocate_video_sink_resource_id());
+ m_active_video_sink = make<ActiveVideoSink>(handle);
m_video_sink_is_ticking = true;
add_current_video_sink(handle);
video_sink_ticking_inputs_changed();
diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Libraries/LibWeb/HTML/HTMLMediaElement.h
index 02bbca0e8b0..e5187ab865d 100644
--- a/Libraries/LibWeb/HTML/HTMLMediaElement.h
+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.h
@@ -14,7 +14,6 @@
#include <AK/Time.h>
#include <AK/Utf16View.h>
#include <AK/Variant.h>
-#include <LibCompositing/DisplayList/DisplayListResourceIds.h>
#include <LibCompositing/Video/VideoFrameHold.h>
#include <LibCore/Forward.h>
#include <LibGC/Function.h>
@@ -229,8 +228,6 @@ public:
void release_presented_video_frame_held_for_callbacks();
virtual void request_rendering_update_for_video_frame_callbacks() { }
- Optional<Compositing::VideoSinkResourceId> video_sink_resource_id() const;
-
virtual void update_representation() { }
protected:
diff --git a/Libraries/LibWeb/Painting/PaintFacts.cpp b/Libraries/LibWeb/Painting/PaintFacts.cpp
index aa45ed621d7..b4895be55f9 100644
--- a/Libraries/LibWeb/Painting/PaintFacts.cpp
+++ b/Libraries/LibWeb/Painting/PaintFacts.cpp
@@ -261,7 +261,6 @@ static void queue_video_paint_facts(HTML::HTMLVideoElement const& element)
auto src_size = video_element.natural_media_size()->to_type<int>();
facts.video_src_width = src_size.width();
facts.video_src_height = src_size.height();
- facts.video_sink_resource_id = video_element.video_sink_resource_id().value().value();
facts.video_sink_handle = sink_handle->value();
}
break;
diff --git a/Libraries/LibWeb/Rust/src/paint_stage.rs b/Libraries/LibWeb/Rust/src/paint_stage.rs
index 16444f1306b..8f1237dff39 100644
--- a/Libraries/LibWeb/Rust/src/paint_stage.rs
+++ b/Libraries/LibWeb/Rust/src/paint_stage.rs
@@ -48,8 +48,6 @@ unsafe extern "C" {
font_count: usize,
image_frames: *const *const c_void,
image_frame_count: usize,
- video_sinks: *const u64,
- video_sink_count: usize,
target_bitmap: *const c_void,
) -> bool;
}
@@ -162,9 +160,8 @@ impl CompositorPoster {
})
}
- /// Stages `fonts`, `image_frames` and `video_sinks`, each a resource id and a sink handle, for the rasterization
- /// `token` names into `target_bitmap`, a shareable `Gfx::Bitmap`, and answers whether the compositor could still be
- /// reached.
+ /// Stages `fonts` and `image_frames` for the rasterization `token` names into `target_bitmap`, a shareable
+ /// `Gfx::Bitmap`, and answers whether the compositor could still be reached.
///
/// # Safety
///
@@ -174,12 +171,10 @@ impl CompositorPoster {
token: u64,
fonts: &[FontHandle],
image_frames: &[ImageFrameHandle],
- video_sinks: &[(u64, u64)],
target_bitmap: *const c_void,
) -> bool {
let fonts: Vec<*const c_void> = fonts.iter().map(FontHandle::as_raw).collect();
let image_frames: Vec<*const c_void> = image_frames.iter().map(ImageFrameHandle::as_raw).collect();
- let video_sinks: Vec<u64> = video_sinks.iter().flat_map(|(id, handle)| [*id, *handle]).collect();
// SAFETY: This holds a reference to the poster, the handles keep the fonts and frames live for the call, in
// which C++ takes references of its own, and the caller keeps the bitmap live for it.
unsafe {
@@ -190,8 +185,6 @@ impl CompositorPoster {
fonts.len(),
image_frames.as_ptr(),
image_frames.len(),
- video_sinks.as_ptr(),
- video_sinks.len() / 2,
target_bitmap,
)
}
@@ -402,8 +395,6 @@ mod ffi_test_stubs {
_: usize,
_: *const *const c_void,
_: usize,
- _: *const u64,
- _: usize,
_: *const c_void,
) -> bool {
true
diff --git a/Libraries/LibWeb/Rust/src/painting/display_list/recorder.rs b/Libraries/LibWeb/Rust/src/painting/display_list/recorder.rs
index cd7e3d75f48..e7c52476620 100644
--- a/Libraries/LibWeb/Rust/src/painting/display_list/recorder.rs
+++ b/Libraries/LibWeb/Rust/src/painting/display_list/recorder.rs
@@ -777,7 +777,7 @@ impl DisplayListRecorder {
pub fn draw_video_frame(
&mut self,
dst_rect: IntRect,
- video_sink_id: VideoSinkResourceId,
+ video_sink_handle: VideoSinkHandle,
scaling_mode: ScalingMode,
) {
if dst_rect.is_empty() {
@@ -786,7 +786,7 @@ impl DisplayListRecorder {
self.append_command(
&DrawVideoFrame {
dst_rect,
- video_sink_id,
+ video_sink_handle,
scaling_mode,
},
&[],
diff --git a/Libraries/LibWeb/Rust/src/painting/display_list_resources.rs b/Libraries/LibWeb/Rust/src/painting/display_list_resources.rs
index dbcd88ba828..2afaa402505 100644
--- a/Libraries/LibWeb/Rust/src/painting/display_list_resources.rs
+++ b/Libraries/LibWeb/Rust/src/painting/display_list_resources.rs
@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-//! What a display list draws besides its tape: fonts, image frames, video sinks and the display lists it nests, which
-//! the list holds for as long as anything holds the list. The compositor is sent the ones it lacks ahead of the list.
+//! What a display list draws besides its tape: fonts, image frames and the display lists it nests, which the list holds
+//! for as long as anything holds the list. The compositor is sent the ones it lacks ahead of the list.
use crate::painting::display_list::builder::RecordedDisplayList;
use crate::painting::display_list::ids::allocate_display_list_id;
@@ -23,8 +23,6 @@ use std::sync::Arc;
pub(crate) struct DisplayListResources {
pub(crate) fonts: HashMap<u64, FontHandle>,
pub(crate) image_frames: HashMap<u64, ImageFrameHandle>,
- /// The handle of each video sink.
- pub(crate) video_sinks: HashMap<u64, u64>,
pub(crate) nested_display_lists: HashMap<u64, Arc<NestedDisplayList>>,
}
@@ -37,9 +35,6 @@ impl DisplayListResources {
for (id, frame) in &other.image_frames {
self.image_frames.entry(*id).or_insert_with(|| frame.clone());
}
- for (id, handle) in &other.video_sinks {
- self.video_sinks.entry(*id).or_insert(*handle);
- }
for (id, display_list) in &other.nested_display_lists {
self.nested_display_lists
.entry(*id)
@@ -87,11 +82,6 @@ impl DisplayListResources {
self.image_frames.entry(*id).or_insert_with(|| frame.clone());
}
}
- for id in &summary.video_sink_ids {
- if let Some(handle) = source.video_sinks.get(id) {
- self.video_sinks.entry(*id).or_insert(*handle);
- }
- }
for id in &summary.display_list_ids {
if let Some(display_list) = source.nested_display_lists.get(id) {
self.nested_display_lists
@@ -105,7 +95,6 @@ impl DisplayListResources {
ResourceIds {
fonts: self.fonts.keys().copied().collect(),
image_frames: self.image_frames.keys().copied().collect(),
- video_sinks: self.video_sinks.keys().copied().collect(),
display_lists: self.nested_display_lists.keys().copied().collect(),
}
}
@@ -116,7 +105,6 @@ impl DisplayListResources {
pub(crate) struct ResourceIds {
pub(crate) fonts: HashSet<u64>,
pub(crate) image_frames: HashSet<u64>,
- pub(crate) video_sinks: HashSet<u64>,
pub(crate) display_lists: HashSet<u64>,
}
diff --git a/Libraries/LibWeb/Rust/src/painting/host/paint.rs b/Libraries/LibWeb/Rust/src/painting/host/paint.rs
index 6f634ae03d7..205fcd8832b 100644
--- a/Libraries/LibWeb/Rust/src/painting/host/paint.rs
+++ b/Libraries/LibWeb/Rust/src/painting/host/paint.rs
@@ -421,7 +421,6 @@ pub struct FfiVideoPaintFacts {
pub has_video_frame: bool,
pub video_src_width: i32,
pub video_src_height: i32,
- pub video_sink_resource_id: u64,
pub video_sink_handle: u64,
pub poster_frame: *const c_void,
}
diff --git a/Libraries/LibWeb/Rust/src/painting/presentation.rs b/Libraries/LibWeb/Rust/src/painting/presentation.rs
index e6230cf1a6e..d4b7b3275db 100644
--- a/Libraries/LibWeb/Rust/src/painting/presentation.rs
+++ b/Libraries/LibWeb/Rust/src/painting/presentation.rs
@@ -365,11 +365,6 @@ impl PresenterState {
update.image_frames.push(frame);
}
}
- for (id, handle) in resources.video_sinks {
- if !held.video_sinks.contains(&id) {
- update.transaction.video_sinks.push((id, handle));
- }
- }
for (id, display_list) in resources.nested_display_lists {
if !held.display_lists.contains(&id) {
update.transaction.display_lists.push(display_list.resource.clone());
@@ -379,7 +374,6 @@ impl PresenterState {
|held: &HashSet<u64>, kept: &HashSet<u64>| -> Vec<u64> { held.difference(kept).copied().collect() };
update.transaction.font_ids_to_remove = removed(&held.fonts, &kept_ids.fonts);
update.transaction.image_frame_ids_to_remove = removed(&held.image_frames, &kept_ids.image_frames);
- update.transaction.video_sink_ids_to_remove = removed(&held.video_sinks, &kept_ids.video_sinks);
update.transaction.display_list_ids_to_remove = removed(&held.display_lists, &kept_ids.display_lists);
self.compositor_resource_ids = kept_ids;
update
diff --git a/Libraries/LibWeb/Rust/src/painting/rasterize.rs b/Libraries/LibWeb/Rust/src/painting/rasterize.rs
index ba9f613f56b..bf6a65854ff 100644
--- a/Libraries/LibWeb/Rust/src/painting/rasterize.rs
+++ b/Libraries/LibWeb/Rust/src/painting/rasterize.rs
@@ -138,13 +138,8 @@ fn post_rasterization(
let resources = resources.with_nested_resources();
let fonts: Vec<FontHandle> = resources.fonts.values().cloned().collect();
let image_frames: Vec<ImageFrameHandle> = resources.image_frames.values().cloned().collect();
- let video_sinks: Vec<(u64, u64)> = resources
- .video_sinks
- .iter()
- .map(|(id, handle)| (*id, *handle))
- .collect();
// SAFETY: The caller keeps the bitmap live for the call.
- if !unsafe { poster.stage_rasterization(token, &fonts, &image_frames, &video_sinks, target_bitmap) } {
+ if !unsafe { poster.stage_rasterization(token, &fonts, &image_frames, target_bitmap) } {
return false;
}
let tree = Arc::new(VisualContextTree::create_identity());
diff --git a/Libraries/LibWeb/Rust/src/painting/record/mod.rs b/Libraries/LibWeb/Rust/src/painting/record/mod.rs
index 0ffa24734d6..d3c7a974899 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/mod.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/mod.rs
@@ -207,14 +207,6 @@ impl<O: Observer> PaintRecorder<'_, O> {
self.resources.note_image_frame(frame)
}
- pub(crate) fn register_video_sink(
- &mut self,
- resource_id: u64,
- sink_handle: u64,
- ) -> crate::painting::display_list::commands::VideoSinkResourceId {
- self.resources.note_video_sink(resource_id, sink_handle)
- }
-
/// The color scheme an SVG image the box `owner` draws renders in: the box's own where it or its document opts into
/// `light` or `dark`, and otherwise the preferred one.
pub(crate) fn vector_image_color_scheme(&self, owner: crate::layout::node_data::NodeSlotId) -> u8 {
diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/replaced.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/replaced.rs
index d67f714144c..bbd76c71890 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/paint/replaced.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/replaced.rs
@@ -13,7 +13,9 @@ use crate::css::css_pixels::{CssPixelRect, CssPixelSize};
use crate::layout::node_data::NodeSlotId;
use crate::layout::replaced_sizing::{Fraction, run_default_sizing_algorithm};
use crate::painting::display_list::builder::PendingInlineClip;
-use crate::painting::display_list::commands::{CanvasId, CompositorContextId, CompositorNestedContextWheelRegion};
+use crate::painting::display_list::commands::{
+ CanvasId, CompositorContextId, CompositorNestedContextWheelRegion, VideoSinkHandle,
+};
use crate::painting::force_dark::ForceDarkRole;
use crate::painting::paintable_geometry::absolute_rect;
use crate::painting::record::PaintRecorder;
@@ -334,8 +336,9 @@ pub(crate) fn paint_video_foreground<O: Observer>(recorder: &mut PaintRecorder<'
);
if !dst_rect.is_empty() {
let scaling_mode = to_gfx_scaling_mode(image_rendering, src_size, (dst_rect.width, dst_rect.height));
- let sink_id = recorder.register_video_sink(video_frame.sink_resource_id, video_frame.sink_handle);
- recorder.recorder.draw_video_frame(dst_rect, sink_id, scaling_mode);
+ recorder
+ .recorder
+ .draw_video_frame(dst_rect, VideoSinkHandle(video_frame.sink_handle), scaling_mode);
}
}
VideoPaintFacts::PosterFrame(Some(poster_frame)) => {
diff --git a/Libraries/LibWeb/Rust/src/painting/record/publish.rs b/Libraries/LibWeb/Rust/src/painting/record/publish.rs
index a949b89d1d0..e541ad70420 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/publish.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/publish.rs
@@ -231,14 +231,12 @@ fn publish_resources(
let RecordingResourceManifest {
fonts,
image_frames,
- video_sinks,
vector_image_render_requests,
..
} = resources;
let mut display_list_resources = DisplayListResources {
fonts: fonts.into_iter().map(|(id, font)| (id.0, font)).collect(),
image_frames,
- video_sinks,
nested_display_lists: HashMap::new(),
};
// The filters of the visual context tree's effects draw these.
diff --git a/Libraries/LibWeb/Rust/src/painting/record/resources.rs b/Libraries/LibWeb/Rust/src/painting/record/resources.rs
index bc4760a5866..48637f412ed 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/resources.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/resources.rs
@@ -6,7 +6,7 @@
use std::collections::HashMap;
-use crate::painting::display_list::commands::{DisplayListResourceId, ImageFrameResourceId, VideoSinkResourceId};
+use crate::painting::display_list::commands::{DisplayListResourceId, ImageFrameResourceId};
use crate::painting::record::vector_images::{VECTOR_IMAGE_PLACEHOLDER_TAG, VectorImageRenderRequest};
use libgfx_rust::font::{FontHandle, FontId};
use libgfx_rust::image_frame::ImageFrameHandle;
@@ -15,7 +15,6 @@ use libgfx_rust::image_frame::ImageFrameHandle;
pub(crate) struct RecordingResourceManifest {
pub(crate) fonts: HashMap<FontId, FontHandle>,
pub(crate) image_frames: HashMap<u64, ImageFrameHandle>,
- pub(crate) video_sinks: HashMap<u64, u64>,
pub(crate) vector_image_render_requests: Vec<VectorImageRenderRequest>,
vector_image_request_indices: HashMap<VectorImageRenderRequest, u32>,
}
@@ -31,11 +30,6 @@ impl RecordingResourceManifest {
ImageFrameResourceId(frame.id())
}
- pub(crate) fn note_video_sink(&mut self, resource_id: u64, sink_handle: u64) -> VideoSinkResourceId {
- self.video_sinks.entry(resource_id).or_insert(sink_handle);
- VideoSinkResourceId(resource_id)
- }
-
pub(crate) fn vector_image_placeholder(&mut self, request: VectorImageRenderRequest) -> DisplayListResourceId {
let next_index = self.vector_image_render_requests.len() as u32;
let index = *self.vector_image_request_indices.entry(request).or_insert_with(|| {
diff --git a/Libraries/LibWeb/Rust/src/painting/replaced_paint_facts.rs b/Libraries/LibWeb/Rust/src/painting/replaced_paint_facts.rs
index 805ade0b25d..074aeb91066 100644
--- a/Libraries/LibWeb/Rust/src/painting/replaced_paint_facts.rs
+++ b/Libraries/LibWeb/Rust/src/painting/replaced_paint_facts.rs
@@ -17,7 +17,6 @@ use libgfx_rust::image_frame::ImageFrameHandle;
pub(crate) struct VideoFrameFacts {
pub src_width: i32,
pub src_height: i32,
- pub sink_resource_id: u64,
pub sink_handle: u64,
}
@@ -43,7 +42,6 @@ impl VideoPaintFacts {
FfiVideoRepresentation::VideoFrame => Self::VideoFrame(facts.has_video_frame.then_some(VideoFrameFacts {
src_width: facts.video_src_width,
src_height: facts.video_src_height,
- sink_resource_id: facts.video_sink_resource_id,
sink_handle: facts.video_sink_handle,
})),
FfiVideoRepresentation::PosterFrame => Self::PosterFrame(
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index 018fa9f51fb..8dae24b27d2 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -501,6 +501,14 @@ CompositorState::VideoSinkState* CompositorState::video_sink_state(CompositorSta
return &sink_state.value();
}
+RefPtr<Media::VideoFrame> CompositorState::current_video_frame(CompositorStateWebContentClient& client, Media::VideoSinkHandle handle)
+{
+ auto* sink_state = video_sink_state(client, handle);
+ if (!sink_state || !sink_state->sink)
+ return nullptr;
+ return sink_state->sink->current_frame();
+}
+
void CompositorState::add_video_sink(CompositorStateWebContentClient& client, Media::VideoSinkHandle handle)
{
auto& sinks = m_video_sink_states.ensure(&client, [] { return HashMap<Media::VideoSinkHandle, VideoSinkState> {}; });
@@ -560,10 +568,6 @@ void CompositorState::on_video_sink_ready(CompositorStateWebContentClient& clien
present_contexts_drawing_video_sink(client, handle);
update_unpainted_video_update_scheduling();
});
- for (auto& [_, context] : m_presented_contexts) {
- if (context->web_content_client.web_content_client_id() == client.web_content_client_id())
- resolve_video_sinks(*context);
- }
present_contexts_drawing_video_sink(client, handle);
update_unpainted_video_update_scheduling();
}
@@ -747,16 +751,6 @@ void CompositorState::present_contexts_drawing_video_sink(CompositorStateWebCont
}
}
-void CompositorState::resolve_video_sinks(PresentedContext& context)
-{
- auto& client = context.web_content_client;
- auto& resource_storage = context.raster_targets.resource_storage();
- for (auto const& [id, handle] : resource_storage.video_sink_handles()) {
- auto* sink_state = video_sink_state(client, handle);
- resource_storage.set_video_sink(Compositing::VideoSinkResourceId { id }, sink_state ? sink_state->sink : nullptr);
- }
-}
-
bool CompositorState::video_sink_is_painted_by_any_context(CompositorStateWebContentClient* client, Media::VideoSinkHandle handle) const
{
for (auto const& [_, context] : m_presented_contexts) {
@@ -824,7 +818,7 @@ bool CompositorState::context_video_sinks_require_updates(Web::CompositorContext
auto* context = presented_context_if_present(context_id);
if (!context)
return false;
- for (auto const& [_, handle] : context->raster_targets.resource_storage().video_sink_handles()) {
+ for (auto handle : context->raster_targets.drawn_video_sinks()) {
if (auto* sink_state = video_sink_state(context->web_content_client, handle); sink_state && sink_state->requires_updates)
return true;
}
@@ -1108,15 +1102,18 @@ CompositorState::PresentedContext& CompositorState::presented_context(Web::Compo
Compositing::RustFFI::FfiRasterPainter CompositorState::begin_painting(Web::CompositorContextId context_id, Gfx::PaintingSurface& surface, RustFFI::PaintingResources resources)
{
- auto& raster_targets = presented_context(context_id).raster_targets;
+ auto& context = presented_context(context_id);
+ auto& raster_targets = context.raster_targets;
if (m_painting_depth == m_display_list_players.size())
m_display_list_players.append(make<DisplayListPlayerSkia>(m_skia_backend_context));
auto& player = *m_display_list_players[m_painting_depth++];
switch (resources) {
case RustFFI::PaintingResources::Page:
- return player.begin_painting(surface, raster_targets.resource_storage(), raster_targets.raster_cache(), &raster_targets.canvas_surfaces());
+ return player.begin_painting(surface, raster_targets.resource_storage(), raster_targets.raster_cache(), &raster_targets.canvas_surfaces(), [this, &client = context.web_content_client](Media::VideoSinkHandle handle) {
+ return current_video_frame(client, handle);
+ });
case RustFFI::PaintingResources::Overlays:
- return player.begin_painting(surface, raster_targets.overlay_resource_storage(), raster_targets.overlay_raster_cache(), nullptr);
+ return player.begin_painting(surface, raster_targets.overlay_resource_storage(), raster_targets.overlay_raster_cache(), nullptr, nullptr);
}
VERIFY_NOT_REACHED();
}
@@ -1199,14 +1196,10 @@ void CompositorState::apply_resource_changes(Web::CompositorContextId context_id
{
auto& context = presented_context(context_id);
Compositing::DisplayListResourceTransaction transaction;
- for (auto const& video_sink : changes.video_sinks)
- transaction.video_sinks.append({ .id = Compositing::VideoSinkResourceId { video_sink.id }, .sink_handle = Media::VideoSinkHandle { video_sink.sink_handle } });
for (auto id : changes.font_ids_to_remove)
transaction.font_ids_to_remove.append(Compositing::FontResourceId { id });
for (auto id : changes.image_frame_ids_to_remove)
transaction.image_frame_ids_to_remove.append(Compositing::ImageFrameResourceId { id });
- for (auto id : changes.video_sink_ids_to_remove)
- transaction.video_sink_ids_to_remove.append(Compositing::VideoSinkResourceId { id });
auto& raster_targets = context.raster_targets;
raster_targets.apply_resource_transaction(move(transaction));
// The display lists that the context's lists nest are held by the logic in Rust, and only their rasters here.
@@ -1214,14 +1207,18 @@ void CompositorState::apply_resource_changes(Web::CompositorContextId context_id
for (auto id : changes.display_list_ids_to_remove)
removed_display_lists.display_lists.set(Compositing::DisplayListResourceId { id });
raster_targets.raster_cache().evict(removed_display_lists);
- resolve_video_sinks(context);
show_animated_image_frames_in(context);
- update_unpainted_video_update_scheduling();
+}
+
+void CompositorState::set_drawn_video_sinks(Web::CompositorContextId context_id, ReadonlySpan<u64> handles)
+{
+ if (presented_context(context_id).raster_targets.set_drawn_video_sinks(handles))
+ update_unpainted_video_update_scheduling();
}
bool CompositorState::stage_rasterization(CompositorStateWebContentClient& client, u64 token, Compositing::DisplayListResourceTransaction&& resources, Gfx::ShareableBitmap target_bitmap)
{
- if (!resources.font_ids_to_remove.is_empty() || !resources.image_frame_ids_to_remove.is_empty() || !resources.video_sink_ids_to_remove.is_empty() || !resources.display_list_ids_to_remove.is_empty())
+ if (!resources.font_ids_to_remove.is_empty() || !resources.image_frame_ids_to_remove.is_empty() || !resources.display_list_ids_to_remove.is_empty())
return false;
// WebContent waits for each rasterization it stages, so it has only the one in flight per thread that rasterizes.
static constexpr size_t maximum_staged_rasterizations_per_client = 16;
@@ -1283,7 +1280,7 @@ bool CompositorState::begin_staged_rasterization(WebContentClientId client, u64
__builtin_memset(target.scanline_u8(0), 0, target.size_in_bytes());
rasterization->target_surface = Gfx::PaintingSurface::wrap_bitmap(target);
rasterization->player = make<DisplayListPlayerSkia>(RefPtr<Gfx::SkiaBackendContext> {});
- painter = rasterization->player->begin_painting(*rasterization->target_surface, rasterization->resource_storage, rasterization->raster_cache, nullptr);
+ painter = rasterization->player->begin_painting(*rasterization->target_surface, rasterization->resource_storage, rasterization->raster_cache, nullptr, nullptr);
return true;
}
@@ -1309,7 +1306,8 @@ static bool video_frame_holds_high_dynamic_range(Media::VideoFrame const& frame)
void CompositorState::report_live_content(Web::CompositorContextId context_id, ReadonlySpan<u64> canvas_ids, void* receiver, void (*receive)(void*, RustFFI::FfiLiveContent const*))
{
- auto& raster_targets = presented_context(context_id).raster_targets;
+ auto& context = presented_context(context_id);
+ auto& raster_targets = context.raster_targets;
auto const& resource_storage = raster_targets.resource_storage();
Vector<RustFFI::FfiCanvasContent> canvases;
@@ -1323,11 +1321,11 @@ void CompositorState::report_live_content(Web::CompositorContextId context_id, R
});
}
Vector<RustFFI::FfiVideoSinkContent> video_sinks;
- video_sinks.ensure_capacity(resource_storage.video_sink_handles().size());
- for (auto const& [id, handle] : resource_storage.video_sink_handles()) {
- auto frame = raster_targets.current_video_frame(Compositing::VideoSinkResourceId { id });
+ video_sinks.ensure_capacity(raster_targets.drawn_video_sinks().size());
+ for (auto handle : raster_targets.drawn_video_sinks()) {
+ auto frame = current_video_frame(context.web_content_client, handle);
video_sinks.unchecked_append({
- .id = id,
+ .handle = handle.value(),
.has_frame = frame != nullptr,
.frame_id = frame ? frame->id() : 0,
.frame_holds_high_dynamic_range = frame && video_frame_holds_high_dynamic_range(*frame),
@@ -1366,7 +1364,7 @@ Optional<RemoteLayer::Content> CompositorState::remote_layer_content(PresentedCo
return RemoteLayer::Content { surface.release_nonnull() };
return {};
case RustFFI::MediaKind::Video:
- if (auto frame = context.raster_targets.current_video_frame(Compositing::VideoSinkResourceId { media_id }))
+ if (auto frame = current_video_frame(context.web_content_client, Media::VideoSinkHandle { media_id }))
return RemoteLayer::Content { frame.release_nonnull() };
return {};
}
@@ -1414,7 +1412,8 @@ bool CompositorState::remote_layer_can_show(Web::CompositorContextId context_id,
Vector<RemoteSublayer>* CompositorState::build_sublayers(Web::CompositorContextId context_id, ReadonlySpan<RustFFI::FfiSublayer> sublayers_to_build)
{
auto sublayers = make<Vector<RemoteSublayer>>();
- auto& raster_targets = presented_context(context_id).raster_targets;
+ auto& context = presented_context(context_id);
+ auto& raster_targets = context.raster_targets;
for (auto const& sublayer : sublayers_to_build) {
Optional<Variant<NonnullRefPtr<Media::VideoFrame>, PresentableSurface::Lease>> content;
switch (sublayer.content_kind) {
@@ -1423,7 +1422,7 @@ Vector<RemoteSublayer>* CompositorState::build_sublayers(Web::CompositorContextI
content = surface->lease();
break;
case RustFFI::SublayerContentKind::Video:
- if (auto frame = raster_targets.current_video_frame(Compositing::VideoSinkResourceId { sublayer.media_id }); frame && frame->surface())
+ if (auto frame = current_video_frame(context.web_content_client, Media::VideoSinkHandle { sublayer.media_id }); frame && frame->surface())
content = frame.release_nonnull();
break;
case RustFFI::SublayerContentKind::PresentableSurface:
@@ -1768,6 +1767,7 @@ RustFFI::FfiRasterHost CompositorState::raster_host(CompositorState& state)
},
.unmap_shared_memory = [](void* mapping) { delete static_cast<SharedMemoryMapping*>(mapping); },
.apply_resource_changes = [](void* host, u64 context_id, RustFFI::FfiResourceChanges const* changes) { state_of(host).apply_resource_changes(Context { context_id }, *changes); },
+ .set_drawn_video_sinks = [](void* host, u64 context_id, ReadonlySpan<u64> handles) { state_of(host).set_drawn_video_sinks(Context { context_id }, handles); },
.staged_rasterization_has_resources = [](void* host, u64 client, u64 token, ReadonlySpan<u64> font_ids, ReadonlySpan<u64> image_frame_ids) { return state_of(host).staged_rasterization_has_resources(WebContentClientId { client }, token, font_ids, image_frame_ids); },
.begin_staged_rasterization = [](void* host, u64 client, u64 token, Compositing::RustFFI::FfiRasterPainter* painter) { return state_of(host).begin_staged_rasterization(WebContentClientId { client }, token, *painter); },
.finish_staged_rasterization = [](void* host, u64 client, u64 token) { state_of(host).finish_staged_rasterization(WebContentClientId { client }, token); },
diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.h
index becc748d4ed..61ef1044321 100644
--- a/Services/Compositor/CompositorState.h
+++ b/Services/Compositor/CompositorState.h
@@ -114,8 +114,8 @@ public:
void set_parent_context(Web::CompositorContextId, Optional<Web::CompositorContextId> parent_context_id);
void stop_presenting_to_client(Web::CompositorContextId);
void update_display_list_resources(Web::CompositorContextId, Compositing::DisplayListResourceTransaction&&);
- // The fonts, image frames and video sinks that the display list of the next rasterization under the token draws, and
- // the bitmap it is rasterized into. Answers false for a token in use, for more rasterizations than a client can have
+ // The fonts and image frames that the display list of the next rasterization under the token draws, and the bitmap
+ // it is rasterized into. Answers false for a token in use, for more rasterizations than a client can have
// in flight, or for resources that a rasterization does not stage.
bool stage_rasterization(CompositorStateWebContentClient&, u64 token, Compositing::DisplayListResourceTransaction&&, Gfx::ShareableBitmap target_bitmap);
void add_video_sink(CompositorStateWebContentClient&, Media::VideoSinkHandle);
@@ -230,6 +230,7 @@ private:
bool add_store_if_window_server_reads_every_released_store(Web::CompositorContextId, Optional<PresentationId>);
bool retire_idle_surplus_stores(Web::CompositorContextId, Optional<PresentationId>);
void apply_resource_changes(Web::CompositorContextId, RustFFI::FfiResourceChanges const&);
+ void set_drawn_video_sinks(Web::CompositorContextId, ReadonlySpan<u64> handles);
struct StagedRasterization;
StagedRasterization* staged_rasterization(WebContentClientId, u64 token);
bool staged_rasterization_has_resources(WebContentClientId, u64 token, ReadonlySpan<u64> font_ids, ReadonlySpan<u64> image_frame_ids);
@@ -258,7 +259,6 @@ private:
};
VideoSinkUpdateResult update_all_video_sinks();
bool context_video_sinks_require_updates(Web::CompositorContextId);
- void resolve_video_sinks(PresentedContext&);
void update_unpainted_video_sinks();
void schedule_unpainted_video_updates();
int unpainted_video_update_interval_ms() const;
@@ -346,6 +346,9 @@ private:
bool requires_updates { false };
};
VideoSinkState* video_sink_state(CompositorStateWebContentClient&, Media::VideoSinkHandle);
+ // The frame that a video sink of the client shows now, which is null for a sink that the client does not have or
+ // that shows none.
+ RefPtr<Media::VideoFrame> current_video_frame(CompositorStateWebContentClient&, Media::VideoSinkHandle);
static bool video_sink_updates_are_needed(VideoSinkState const&);
bool video_sink_is_painted_by_any_context(CompositorStateWebContentClient*, Media::VideoSinkHandle) const;
void update_unpainted_video_update_scheduling();
diff --git a/Services/Compositor/CompositorWebContentServer.ipc b/Services/Compositor/CompositorWebContentServer.ipc
index 09c3703f3b3..7b762205208 100644
--- a/Services/Compositor/CompositorWebContentServer.ipc
+++ b/Services/Compositor/CompositorWebContentServer.ipc
@@ -63,9 +63,9 @@ endpoint CompositorWebContentServer
commit_placeholder_canvas(Compositing::CanvasId canvas_id, u64 secret, Optional<Compositing::CanvasId> source_canvas_id, Gfx::IntSize size, bool origin_clean) =|
get_placeholder_canvas_pixels(Compositing::CanvasId canvas_id, Gfx::IntRect rect) => (Gfx::ShareableBitmap pixels, bool origin_clean)
- // A display list is rasterized into the target bitmap with the fonts, image frames and video sinks staged for it under
- // 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().
+ // A display list is rasterized into the target bitmap with the fonts and image frames staged for it under 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, Compositing::DisplayList display_list, Compositing::VisualContextTree visual_context_tree, Compositing::DisplayListResourceTransaction nested_display_lists) =|
diff --git a/Services/Compositor/ContextRasterTargets.cpp b/Services/Compositor/ContextRasterTargets.cpp
index b330c8fcf16..ec77838126c 100644
--- a/Services/Compositor/ContextRasterTargets.cpp
+++ b/Services/Compositor/ContextRasterTargets.cpp
@@ -8,7 +8,6 @@
#include <Compositor/FontSkia.h>
#include <LibGfx/Font/Font.h>
#include <LibGfx/Font/FontDatabase.h>
-#include <LibMedia/Sinks/VideoSink.h>
#include <core/SkFont.h>
#include <core/SkFontMetrics.h>
#include <core/SkFontTypes.h>
@@ -66,21 +65,22 @@ RefPtr<PresentableSurface> ContextRasterTargets::next_presentable_surface(u32 po
return surface.release_value();
}
-RefPtr<Media::VideoFrame> ContextRasterTargets::current_video_frame(Compositing::VideoSinkResourceId video_sink_id) const
+bool ContextRasterTargets::set_drawn_video_sinks(ReadonlySpan<u64> handles)
{
- auto sink = m_resource_storage.video_sink(video_sink_id);
- if (!sink)
- return {};
- return sink->current_frame();
-}
-
-bool ContextRasterTargets::draws_video_sink(Media::VideoSinkHandle handle) const
-{
- for (auto const& [id, sink_handle] : m_resource_storage.video_sink_handles()) {
- if (sink_handle == handle)
- return true;
+ HashTable<Media::VideoSinkHandle> drawn_video_sinks;
+ for (auto handle : handles)
+ drawn_video_sinks.set(Media::VideoSinkHandle { handle });
+ bool changed = drawn_video_sinks.size() != m_drawn_video_sinks.size();
+ for (auto handle : m_drawn_video_sinks) {
+ if (drawn_video_sinks.contains(handle))
+ continue;
+ m_raster_cache.forget_video_sink(handle);
+ changed = true;
}
- return false;
+ if (!changed)
+ return false;
+ m_drawn_video_sinks = move(drawn_video_sinks);
+ return true;
}
}
diff --git a/Services/Compositor/ContextRasterTargets.h b/Services/Compositor/ContextRasterTargets.h
index a34f7c75e40..3ccce54179e 100644
--- a/Services/Compositor/ContextRasterTargets.h
+++ b/Services/Compositor/ContextRasterTargets.h
@@ -7,9 +7,11 @@
#pragma once
#include <AK/HashMap.h>
+#include <AK/HashTable.h>
#include <AK/Noncopyable.h>
#include <AK/Optional.h>
#include <AK/RefPtr.h>
+#include <AK/Span.h>
#include <AK/StringView.h>
#include <Compositor/BackingStoreManager.h>
#include <Compositor/CanvasSurfaceRegistry.h>
@@ -18,7 +20,7 @@
#include <Compositor/PresentableSurface.h>
#include <LibCompositing/DisplayList/DisplayListResourceStorage.h>
#include <LibGfx/Size.h>
-#include <LibMediaCodecs/VideoFrame.h>
+#include <LibMedia/VideoSinkHandle.h>
namespace Gfx {
@@ -57,8 +59,11 @@ public:
RefPtr<PresentableSurface> next_presentable_surface(u32 pool, Gfx::IntSize, RefPtr<Gfx::SkiaBackendContext> const&);
void drop_presentable_surface_pool(u32 pool) { m_presentable_surface_pools.remove(pool); }
- RefPtr<Media::VideoFrame> current_video_frame(Compositing::VideoSinkResourceId) const;
- bool draws_video_sink(Media::VideoSinkHandle) const;
+ // The video sinks that the display list of the context and the lists it nests draw. Answers whether these are
+ // other sinks than before.
+ bool set_drawn_video_sinks(ReadonlySpan<u64> handles);
+ HashTable<Media::VideoSinkHandle> const& drawn_video_sinks() const { return m_drawn_video_sinks; }
+ bool draws_video_sink(Media::VideoSinkHandle handle) const { return m_drawn_video_sinks.contains(handle); }
private:
Compositing::DisplayListResourceStorage m_resource_storage;
@@ -68,6 +73,7 @@ private:
DisplayListRasterCache m_overlay_raster_cache;
BackingStoreManager m_backing_stores;
HashMap<u32, PresentableSurfacePool> m_presentable_surface_pools;
+ HashTable<Media::VideoSinkHandle> m_drawn_video_sinks;
};
}
diff --git a/Services/Compositor/DisplayListPlayerSkia.cpp b/Services/Compositor/DisplayListPlayerSkia.cpp
index b7c519b8ee8..2ed0a6387e0 100644
--- a/Services/Compositor/DisplayListPlayerSkia.cpp
+++ b/Services/Compositor/DisplayListPlayerSkia.cpp
@@ -128,13 +128,14 @@ struct DisplayListPlayerSkia::PainterCallbacks {
}
};
-RustFFI::FfiRasterPainter DisplayListPlayerSkia::begin_painting(Gfx::PaintingSurface& surface, DisplayListResourceStorage const& resource_storage, DisplayListRasterCache& raster_cache, OwnedCanvasSurfaces const* canvas_surfaces)
+RustFFI::FfiRasterPainter DisplayListPlayerSkia::begin_painting(Gfx::PaintingSurface& surface, DisplayListResourceStorage const& resource_storage, DisplayListRasterCache& raster_cache, OwnedCanvasSurfaces const* canvas_surfaces, CurrentVideoFrame current_video_frame)
{
VERIFY(m_surfaces.is_empty());
m_surfaces.append(surface);
m_resource_storage = &resource_storage;
m_raster_cache = &raster_cache;
m_canvas_surfaces = canvas_surfaces;
+ m_current_video_frame = move(current_video_frame);
return PainterCallbacks::for_player(*this);
}
@@ -148,6 +149,7 @@ void DisplayListPlayerSkia::end_painting()
m_resource_storage = nullptr;
m_raster_cache = nullptr;
m_canvas_surfaces = nullptr;
+ m_current_video_frame = nullptr;
}
void DisplayListPlayerSkia::play_command_bytes(DisplayListCommandType command_type, u8 const* command, ReadonlyBytes payload)
@@ -399,8 +401,14 @@ void DisplayListPlayerSkia::play_command(DrawCanvas const& command)
void DisplayListPlayerSkia::play_command(DrawVideoFrame const& command)
{
+ if (!m_current_video_frame)
+ return;
+ auto frame = m_current_video_frame(command.video_sink_handle);
+ if (!frame)
+ return;
+
Gfx::IntSize visible_size;
- auto image = raster_cache().image_for_video_sink(resource_storage(), command.video_sink_id, m_skia_backend_context, visible_size);
+ auto image = raster_cache().image_for_video_sink(command.video_sink_handle, *frame, m_skia_backend_context, visible_size);
if (!image)
return;
diff --git a/Services/Compositor/DisplayListPlayerSkia.h b/Services/Compositor/DisplayListPlayerSkia.h
index 88c39562424..ca6af75e2ee 100644
--- a/Services/Compositor/DisplayListPlayerSkia.h
+++ b/Services/Compositor/DisplayListPlayerSkia.h
@@ -18,6 +18,8 @@
#include <LibCompositing/RustFFI.h>
#include <LibGfx/Forward.h>
#include <LibGfx/Rect.h>
+#include <LibMedia/VideoSinkHandle.h>
+#include <LibMediaCodecs/VideoFrame.h>
class GrDirectContext;
class SkColorFilter;
@@ -46,9 +48,12 @@ public:
explicit DisplayListPlayerSkia(RefPtr<Gfx::SkiaBackendContext>);
~DisplayListPlayerSkia();
+ // Answers the frame that a video sink shows now, which is null for a sink that shows none.
+ using CurrentVideoFrame = Function<RefPtr<Media::VideoFrame>(Media::VideoSinkHandle)>;
+
// The painter paints into `surface`, with the resources of `resource_storage` and the caches of `raster_cache`,
- // until end_painting().
- Compositing::RustFFI::FfiRasterPainter begin_painting(Gfx::PaintingSurface&, Compositing::DisplayListResourceStorage const&, DisplayListRasterCache&, OwnedCanvasSurfaces const*);
+ // until end_painting(). It draws no canvas without `canvas_surfaces`, and no video without `current_video_frame`.
+ Compositing::RustFFI::FfiRasterPainter begin_painting(Gfx::PaintingSurface&, Compositing::DisplayListResourceStorage const&, DisplayListRasterCache&, OwnedCanvasSurfaces const*, CurrentVideoFrame);
void end_painting();
static void flush(Gfx::PaintingSurface&);
@@ -126,6 +131,7 @@ private:
Compositing::DisplayListResourceStorage const* m_resource_storage { nullptr };
DisplayListRasterCache* m_raster_cache { nullptr };
OwnedCanvasSurfaces const* m_canvas_surfaces { nullptr };
+ CurrentVideoFrame m_current_video_frame;
ReadonlyBytes m_current_command_payload;
// The tile and nested display list rasters the painter replays into, which hold Skia objects.
diff --git a/Services/Compositor/DisplayListRasterCache.cpp b/Services/Compositor/DisplayListRasterCache.cpp
index 3f1cf1d5590..8b187509582 100644
--- a/Services/Compositor/DisplayListRasterCache.cpp
+++ b/Services/Compositor/DisplayListRasterCache.cpp
@@ -195,8 +195,6 @@ void DisplayListRasterCache::evict(DisplayListResourceSet const& removed_resourc
m_layer_image_filter_cache = nullptr;
for (auto id : removed_resources.image_frames)
m_image_frame_images.remove(id.value());
- for (auto id : removed_resources.video_sinks)
- m_video_sink_images.remove(id.value());
for (auto id : removed_resources.display_lists)
m_nested_display_list_rasters.remove(id.value());
if (!removed_resources.fonts.is_empty()) {
@@ -278,22 +276,20 @@ sk_sp<SkImage> DisplayListRasterCache::image_for_image_frame(DisplayListResource
return image;
}
-sk_sp<SkImage> DisplayListRasterCache::image_for_video_sink(DisplayListResourceStorage const& resource_storage, VideoSinkResourceId id, RefPtr<Gfx::SkiaBackendContext> const& skia_backend_context, Gfx::IntSize& visible_size)
+void DisplayListRasterCache::forget_video_sink(Media::VideoSinkHandle handle)
{
- auto sink = resource_storage.video_sink(id);
- if (!sink)
- return nullptr;
- auto frame = sink->current_frame();
- if (!frame)
- return nullptr;
+ m_video_sink_images.remove(handle.value());
+}
- auto& cached_image = *m_video_sink_images.ensure(id.value(), [] { return make<VideoSinkImage>(); });
+sk_sp<SkImage> DisplayListRasterCache::image_for_video_sink(Media::VideoSinkHandle handle, Media::VideoFrame const& frame, RefPtr<Gfx::SkiaBackendContext> const& skia_backend_context, Gfx::IntSize& visible_size)
+{
+ auto& cached_image = *m_video_sink_images.ensure(handle.value(), [] { return make<VideoSinkImage>(); });
auto cached_image_matches = [&] {
if (!cached_image.image)
return false;
if (cached_image.skia_backend_context != skia_backend_context)
return false;
- return cached_image.frame_id == frame->id();
+ return cached_image.frame_id == frame.id();
}();
if (cached_image_matches) {
cached_image.drawn_frame = frame;
@@ -301,15 +297,15 @@ sk_sp<SkImage> DisplayListRasterCache::image_for_video_sink(DisplayListResourceS
return cached_image.image;
}
- auto image = sk_image_from_video_frame(*frame, skia_backend_context);
+ auto image = sk_image_from_video_frame(frame, skia_backend_context);
if (!image)
return nullptr;
- cached_image.frame_id = frame->id();
+ cached_image.frame_id = frame.id();
cached_image.drawn_frame = frame;
cached_image.skia_backend_context = skia_backend_context;
cached_image.image = image;
- cached_image.visible_size = frame->size().to_type<int>();
+ cached_image.visible_size = frame.size().to_type<int>();
visible_size = cached_image.visible_size;
return image;
}
diff --git a/Services/Compositor/DisplayListRasterCache.h b/Services/Compositor/DisplayListRasterCache.h
index d8d5d3b7266..67a45ddf8e5 100644
--- a/Services/Compositor/DisplayListRasterCache.h
+++ b/Services/Compositor/DisplayListRasterCache.h
@@ -20,6 +20,8 @@
#include <LibGfx/Forward.h>
#include <LibGfx/Rect.h>
#include <LibGfx/Size.h>
+#include <LibMedia/VideoSinkHandle.h>
+#include <LibMediaCodecs/Forward.h>
class SkImage;
class SkImageFilter;
@@ -74,10 +76,13 @@ public:
// Drops everything made from these resources, which the storage removed or replaced.
void evict(Compositing::DisplayListResourceSet const& removed_resources);
+ // Drops the image made from the frame of a video sink that is no longer drawn.
+ void forget_video_sink(Media::VideoSinkHandle);
sk_sp<SkImage> image_for_image_frame(Compositing::DisplayListResourceStorage const&, Compositing::ImageFrameResourceId, RefPtr<Gfx::SkiaBackendContext> const&);
- // The image can be larger than the frame, whose visible size is the part of it to draw.
- sk_sp<SkImage> image_for_video_sink(Compositing::DisplayListResourceStorage const&, Compositing::VideoSinkResourceId, RefPtr<Gfx::SkiaBackendContext> const&, Gfx::IntSize& visible_size);
+ // The image of the frame that the video sink shows. The image can be larger than the frame, whose visible size is
+ // the part of it to draw.
+ sk_sp<SkImage> image_for_video_sink(Media::VideoSinkHandle, Media::VideoFrame const&, RefPtr<Gfx::SkiaBackendContext> const&, Gfx::IntSize& visible_size);
sk_sp<SkImage> repeated_tile_raster(u64 tile_key, Gfx::IntSize, RefPtr<Gfx::SkiaBackendContext> const&) const;
void add_repeated_tile_raster(u64 tile_key, Gfx::IntSize, RefPtr<Gfx::SkiaBackendContext> const&, sk_sp<SkImage>);
sk_sp<SkImage> nested_display_list_raster(Compositing::DisplayListResourceId, RefPtr<Gfx::SkiaBackendContext> const&, Gfx::IntRect visible_rect_in_list_space, Gfx::IntRect& raster_rect_in_list_space);
diff --git a/Services/Compositor/Rust/build.rs b/Services/Compositor/Rust/build.rs
index 5bc5e0b3225..a01028d5b7d 100644
--- a/Services/Compositor/Rust/build.rs
+++ b/Services/Compositor/Rust/build.rs
@@ -34,7 +34,6 @@ fn main() -> Result<(), Box<dyn Error>> {
("FfiReplaySelection", "Compositing::RustFFI::FfiReplaySelection"),
("RecordSpan", "Compositing::RustFFI::RecordSpan"),
("CanvasId", "Compositing::CanvasId"),
- ("VideoSinkResourceId", "Compositing::VideoSinkResourceId"),
("ImageFrameResourceId", "Compositing::ImageFrameResourceId"),
] {
config.export.rename.insert(rust_name.to_string(), cpp_name.to_string());
diff --git a/Services/Compositor/Rust/src/context_state/mod.rs b/Services/Compositor/Rust/src/context_state/mod.rs
index 68752a4efb1..cda27ae4ea7 100644
--- a/Services/Compositor/Rust/src/context_state/mod.rs
+++ b/Services/Compositor/Rust/src/context_state/mod.rs
@@ -469,6 +469,15 @@ impl ContextState {
pub fn nested_display_lists_mut(&mut self) -> &mut NestedDisplayListStore {
Rc::make_mut(&mut self.nested_display_lists)
}
+ /// The handles of the video sinks that the display list and the lists it nests draw.
+ pub fn video_sink_handles_drawn(&self) -> Vec<u64> {
+ match self.scene.display_list() {
+ Some(display_list) => self
+ .nested_display_lists
+ .video_sink_handles_drawn_by(display_list.storage()),
+ None => Vec::new(),
+ }
+ }
pub fn context_id(&self) -> CompositorContextId {
self.context_id
}
diff --git a/Services/Compositor/Rust/src/core/messages.rs b/Services/Compositor/Rust/src/core/messages.rs
index 391bc2b0fba..750354becb1 100644
--- a/Services/Compositor/Rust/src/core/messages.rs
+++ b/Services/Compositor/Rust/src/core/messages.rs
@@ -236,7 +236,7 @@ impl MessagesFromWebContent<'_> {
}
};
let transaction = message.nested_display_lists;
- if transaction.removes_anything() || !transaction.video_sinks.is_empty() {
+ if transaction.removes_anything() {
return not_rasterized("Resource transaction holds more than the display lists it nests");
}
let mut nested_display_lists = NestedDisplayListStore::default();
diff --git a/Services/Compositor/Rust/src/core/mod.rs b/Services/Compositor/Rust/src/core/mod.rs
index b8edaa486af..2fb700224b9 100644
--- a/Services/Compositor/Rust/src/core/mod.rs
+++ b/Services/Compositor/Rust/src/core/mod.rs
@@ -19,7 +19,7 @@ use crate::host::{
};
use crate::overlays::UIOverlays;
use crate::presenting::ContextPresenting;
-use crate::raster_host::{FfiResourceChanges, FfiVideoSinkResource, RasterHost, SurfaceHandle};
+use crate::raster_host::{FfiResourceChanges, RasterHost, SurfaceHandle};
use crate::wheel_gesture_routing::WheelGestureIdAllocator;
use libcompositing_rust::ipc_types::Compositing_ContextVisibility as ContextVisibility;
use libcompositing_rust::ipc_types::Compositing_DisplayListResourceTransaction;
@@ -690,8 +690,9 @@ impl CompositorCore {
installed
}
- /// Adds and removes the resources that a display list or a visual context tree that the context took comes with.
- /// Answers false, changing nothing, for display lists that would nest themselves.
+ /// Adds and removes the resources that a display list or a visual context tree that the context took comes with,
+ /// and tells the host which video sinks the context draws with them. Answers false, changing nothing, for display
+ /// lists that would nest themselves.
pub fn apply_resource_transaction(
&self,
context_id: CompositorContextId,
@@ -702,7 +703,7 @@ impl CompositorCore {
let Some(context) = self.context_if_present(context_id) else {
return true;
};
- let changes_resources_held_by_the_host = !transaction.video_sinks.is_empty() || transaction.removes_anything();
+ let removes_resources_held_by_the_host = transaction.removes_anything();
if !transaction.display_lists.is_empty() || !transaction.display_list_ids_to_remove.is_empty() {
let mut context = context.borrow_mut();
let nested_display_lists = context.nested_display_lists_mut();
@@ -713,24 +714,18 @@ impl CompositorCore {
nested_display_lists.remove(display_list_id);
}
}
- if !changes_resources_held_by_the_host {
- return true;
+ if removes_resources_held_by_the_host {
+ self.raster.apply_resource_changes(
+ context_id,
+ &FfiResourceChanges {
+ font_ids_to_remove: ak::Span::new(&transaction.font_ids_to_remove),
+ image_frame_ids_to_remove: ak::Span::new(&transaction.image_frame_ids_to_remove),
+ display_list_ids_to_remove: ak::Span::new(&transaction.display_list_ids_to_remove),
+ },
+ );
}
- let video_sinks: Vec<FfiVideoSinkResource> = transaction
- .video_sinks
- .iter()
- .map(|&(id, sink_handle)| FfiVideoSinkResource { id, sink_handle })
- .collect();
- self.raster.apply_resource_changes(
- context_id,
- &FfiResourceChanges {
- video_sinks: ak::Span::new(&video_sinks),
- font_ids_to_remove: ak::Span::new(&transaction.font_ids_to_remove),
- image_frame_ids_to_remove: ak::Span::new(&transaction.image_frame_ids_to_remove),
- video_sink_ids_to_remove: ak::Span::new(&transaction.video_sink_ids_to_remove),
- display_list_ids_to_remove: ak::Span::new(&transaction.display_list_ids_to_remove),
- },
- );
+ let video_sink_handles = context.borrow().video_sink_handles_drawn();
+ self.raster.set_drawn_video_sinks(context_id, &video_sink_handles);
true
}
diff --git a/Services/Compositor/Rust/src/nested_display_lists.rs b/Services/Compositor/Rust/src/nested_display_lists.rs
index 2849a93173a..cfe8b9b4e8d 100644
--- a/Services/Compositor/Rust/src/nested_display_lists.rs
+++ b/Services/Compositor/Rust/src/nested_display_lists.rs
@@ -9,7 +9,7 @@
use libcompositing_rust::display_list::replay::{NestedDisplayList, NestedDisplayLists};
use libcompositing_rust::display_list::storage::DisplayListStorage;
-use libcompositing_rust::display_list::summary::requires_direct_replay_without_nested_lists;
+use libcompositing_rust::display_list::summary::{DisplayListSummary, requires_direct_replay_without_nested_lists};
use libcompositing_rust::ipc_types::NestedDisplayListResource;
use libcompositing_rust::visual_context::VisualContextTree;
use libgfx_rust::Color;
@@ -129,9 +129,11 @@ impl NestedDisplayListStore {
})
}
- /// The canvases that the lists a list nests draw, at any depth.
- pub fn canvas_ids_of_nested_display_lists(&self, storage: &DisplayListStorage) -> HashSet<u64> {
- let mut canvas_ids = HashSet::new();
+ fn for_each_summary_of_nested_display_lists(
+ &self,
+ storage: &DisplayListStorage,
+ mut visit: impl FnMut(&DisplayListSummary),
+ ) {
let mut visited = HashSet::new();
let mut pending: Vec<u64> = storage.summary().display_list_ids.clone();
while let Some(display_list_id) = pending.pop() {
@@ -140,13 +142,30 @@ impl NestedDisplayListStore {
}
if let Some(nested) = self.display_lists.get(&display_list_id) {
let summary = nested.storage.summary();
- canvas_ids.extend(&summary.canvas_ids);
+ visit(summary);
pending.extend(&summary.display_list_ids);
}
}
+ }
+
+ /// The canvases that the lists a list nests draw, at any depth.
+ pub fn canvas_ids_of_nested_display_lists(&self, storage: &DisplayListStorage) -> HashSet<u64> {
+ let mut canvas_ids = HashSet::new();
+ self.for_each_summary_of_nested_display_lists(storage, |summary| canvas_ids.extend(&summary.canvas_ids));
canvas_ids
}
+ /// The handles of the video sinks that a list and the lists it nests draw, at any depth.
+ pub fn video_sink_handles_drawn_by(&self, storage: &DisplayListStorage) -> Vec<u64> {
+ let mut handles = storage.summary().video_sink_handles.clone();
+ self.for_each_summary_of_nested_display_lists(storage, |summary| {
+ handles.extend(&summary.video_sink_handles);
+ });
+ handles.sort_unstable();
+ handles.dedup();
+ handles
+ }
+
// A raster of a list can differ from replaying it in place when a destination-reading operation can see what was
// painted before the list began, or when the list draws live content that changes under its immutable commands.
// A nested list's live content matters at any depth, and its unisolated destination reads matter when its command
diff --git a/Services/Compositor/Rust/src/presenting/damage.rs b/Services/Compositor/Rust/src/presenting/damage.rs
index 1a23bd895a2..a09901deb80 100644
--- a/Services/Compositor/Rust/src/presenting/damage.rs
+++ b/Services/Compositor/Rust/src/presenting/damage.rs
@@ -12,7 +12,7 @@ use crate::frame_inputs::FrameInputs;
use crate::host::PendingFrame;
use crate::nested_display_lists::NestedDisplayListStore;
use crate::raster_host::LiveContent;
-use libcompositing_rust::display_list::commands::{CanvasId, ImageFrameResourceId, VideoSinkResourceId};
+use libcompositing_rust::display_list::commands::{CanvasId, ImageFrameResourceId, VideoSinkHandle};
use libcompositing_rust::display_list::damage::{DisplayListDamage, LayerPlans, LiveContentChanges};
use libcompositing_rust::display_list::summary::LiveContent as LiveMedia;
use libcompositing_rust::scrolling::DisplayList;
@@ -78,7 +78,7 @@ impl StoreDamage {
#[derive(Default)]
pub struct LiveContentChangesSinceLastPaint {
pub canvases: Vec<CanvasId>,
- pub video_sinks: Vec<VideoSinkResourceId>,
+ pub video_sinks: Vec<VideoSinkHandle>,
pub image_frames: Vec<ImageFrameResourceId>,
pub media_updates: Vec<MediaUpdate>,
pub repaints_everything: bool,
@@ -143,11 +143,11 @@ impl ContextPresenting {
.into_iter()
.map(|id| (id, canvas_generation(id)))
.collect();
- // Every video the context holds is drawn by the list or by a display list it nests.
+ // The host reports the video sinks that the list and the display lists it nests draw.
let video_frame_ids = live_content
.video_sinks
.values()
- .map(|sink| (sink.id, sink.has_frame.then_some(sink.frame_id)))
+ .map(|sink| (sink.handle, sink.has_frame.then_some(sink.frame_id)))
.collect();
let image_frame_pixel_generations = live_content.image_frames.clone();
self.painted_frame = Some(PaintedFrame {
@@ -202,25 +202,25 @@ impl ContextPresenting {
}
let summary = display_list.storage().summary();
let image_frame_ids_of_list: HashSet<u64> = summary.image_frame_ids.iter().copied().collect();
- let video_sink_ids_of_list: HashSet<u64> = summary.video_sink_ids.iter().copied().collect();
- for (video_sink_id, frame_id) in &painted_frame.video_frame_ids {
+ let video_sink_handles_of_list: HashSet<u64> = summary.video_sink_handles.iter().copied().collect();
+ for (video_sink_handle, frame_id) in &painted_frame.video_frame_ids {
let current_frame_id = live_content
.video_sinks
- .get(video_sink_id)
+ .get(video_sink_handle)
.and_then(|sink| sink.has_frame.then_some(sink.frame_id));
if current_frame_id == *frame_id {
continue;
}
changes.media_updates.push(MediaUpdate {
- media: LiveMedia::VideoFrame(VideoSinkResourceId(*video_sink_id)),
+ media: LiveMedia::VideoFrame(VideoSinkHandle(*video_sink_handle)),
content_version: current_frame_id.unwrap_or(0),
});
// A video drawn only by a nested display list, such as an SVG image's, has no command in this list to
// damage.
- if !video_sink_ids_of_list.contains(video_sink_id) {
+ if !video_sink_handles_of_list.contains(video_sink_handle) {
changes.repaints_everything = true;
}
- changes.video_sinks.push(VideoSinkResourceId(*video_sink_id));
+ changes.video_sinks.push(VideoSinkHandle(*video_sink_handle));
}
for (&image_frame_id, &pixel_generation) in &live_content.image_frames {
if painted_frame.image_frame_pixel_generations.get(&image_frame_id) == Some(&pixel_generation) {
diff --git a/Services/Compositor/Rust/src/presenting/layers.rs b/Services/Compositor/Rust/src/presenting/layers.rs
index 03d67f6b78d..0c3537fec18 100644
--- a/Services/Compositor/Rust/src/presenting/layers.rs
+++ b/Services/Compositor/Rust/src/presenting/layers.rs
@@ -15,7 +15,7 @@ use crate::raster_host::{
FfiSublayer, FfiSublayerPlacement, LiveContent, MediaKind, PresentableSurfaceHandle, SublayerContentKind,
SurfaceBlend, SurfaceHandle,
};
-use libcompositing_rust::display_list::commands::{CanvasId, VideoSinkResourceId};
+use libcompositing_rust::display_list::commands::{CanvasId, VideoSinkHandle};
use libcompositing_rust::display_list::layers::{LayerKind, LayerPlan, LayerPlanInputs, build_layer_plan};
use libcompositing_rust::display_list::summary::LiveContent as LiveMedia;
use libcompositing_rust::display_list::window_server_placement::WindowServerPlacement;
@@ -202,7 +202,7 @@ impl LayerUpdate {
pub fn rect_of_media_layers_showing(
plan: &LayerPlan,
canvases: &[CanvasId],
- video_sinks: &[VideoSinkResourceId],
+ video_sinks: &[VideoSinkHandle],
) -> IntRect {
let mut rect = IntRect::default();
for layer in &plan.layers {
@@ -274,14 +274,14 @@ impl ContextPresenting {
&& env.raster.remote_layer_can_show_high_dynamic_range(env.context_id)
&& env.window_server_may_show_high_dynamic_range
{
- for id in &frame.display_list.storage().summary().video_sink_ids {
- let media = LiveMedia::VideoFrame(VideoSinkResourceId(*id));
+ for handle in &frame.display_list.storage().summary().video_sink_handles {
+ let media = LiveMedia::VideoFrame(VideoSinkHandle(*handle));
if layers.active_media.contains(&media) {
continue;
}
let holds_high_dynamic_range = live_content
.video_sinks
- .get(id)
+ .get(handle)
.is_some_and(|sink| sink.has_frame && sink.frame_holds_high_dynamic_range);
if holds_high_dynamic_range {
layers.active_media.push(media);
diff --git a/Services/Compositor/Rust/src/raster_host.rs b/Services/Compositor/Rust/src/raster_host.rs
index e893b5dc163..9c02c50c06c 100644
--- a/Services/Compositor/Rust/src/raster_host.rs
+++ b/Services/Compositor/Rust/src/raster_host.rs
@@ -106,7 +106,7 @@ pub struct FfiCanvasContent {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[repr(C)]
pub struct FfiVideoSinkContent {
- pub id: u64,
+ pub handle: u64,
pub has_frame: bool,
pub frame_id: u64,
pub frame_holds_high_dynamic_range: bool,
@@ -114,22 +114,11 @@ pub struct FfiVideoSinkContent {
pub frame_has_surface: bool,
}
-/// A video sink that a display list draws: its resource ID, and the handle of the sink.
-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
-#[repr(C)]
-pub struct FfiVideoSinkResource {
- pub id: u64,
- pub sink_handle: u64,
-}
-
-/// The resources of a context that a display list or a visual context tree it accepted adds or removes, apart from the
-/// fonts and image frames that went ahead of it.
+/// The resources of a context that a display list or a visual context tree it accepted removes.
#[repr(C)]
pub struct FfiResourceChanges<'a> {
- pub video_sinks: ak::Span<'a, FfiVideoSinkResource>,
pub font_ids_to_remove: ak::Span<'a, u64>,
pub image_frame_ids_to_remove: ak::Span<'a, u64>,
- pub video_sink_ids_to_remove: ak::Span<'a, u64>,
pub display_list_ids_to_remove: ak::Span<'a, u64>,
}
@@ -140,8 +129,8 @@ pub struct FfiImageFrameContent {
pub pixel_generation: u64,
}
-/// The live content of a context as it is now: the canvases asked about, every video sink and every image frame the
-/// context's resources hold.
+/// The live content of a context as it is now: the canvases asked about, every video sink the context draws and every
+/// image frame its resources hold.
#[repr(C)]
pub struct FfiLiveContent<'a> {
pub canvases: ak::Span<'a, FfiCanvasContent>,
@@ -149,8 +138,8 @@ pub struct FfiLiveContent<'a> {
pub image_frames: ak::Span<'a, FfiImageFrameContent>,
}
-/// The live content of a context as it is now, by ID: the canvases asked about, every video sink, and the pixel
-/// generation of every image frame.
+/// The live content of a context as it is now: the canvases asked about by ID, every video sink the context draws by
+/// its handle, and the pixel generation of every image frame by ID.
#[derive(Clone, Default, Debug)]
pub struct LiveContent {
pub canvases: HashMap<u64, FfiCanvasContent>,
@@ -191,7 +180,8 @@ pub enum SublayerContentKind {
PresentableSurface,
}
-/// A sublayer the window server shows above a frame: a canvas or video of the context by its id, or a surface.
+/// A sublayer the window server shows above a frame: a canvas of the context by its id, a video by the handle of its
+/// sink, or a surface.
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct FfiSublayer {
@@ -317,9 +307,11 @@ pub struct FfiRasterHost {
pub map_shared_memory: unsafe extern "C" fn(*mut c_void, i32, u64, *mut *const u8, *mut usize) -> *mut c_void,
pub unmap_shared_memory: unsafe extern "C" fn(*mut c_void),
pub apply_resource_changes: unsafe extern "C" fn(*mut c_void, u64, *const FfiResourceChanges<'_>),
+ /// Arguments: the context, and the handles of the video sinks that its display list and the lists it nests draw.
+ pub set_drawn_video_sinks: unsafe extern "C" fn(*mut c_void, u64, ak::Span<'_, u64>),
/// Arguments: the client, the token it staged the rasterization under, and the fonts and image frames the display
- /// list draws. Answers whether the rasterization is staged with all of them. A video sink drawn without a handle
- /// draws nothing, so the sinks are not asked about.
+ /// list draws. Answers whether the rasterization is staged with all of them. A staged rasterization draws no video
+ /// frames, so the sinks are not asked about.
pub staged_rasterization_has_resources:
unsafe extern "C" fn(*mut c_void, u64, u64, ak::Span<'_, u64>, ak::Span<'_, u64>) -> bool,
/// Writes the painter that paints into the target of the staged rasterization, with its resources, until
@@ -659,7 +651,7 @@ impl RasterHost {
.video_sinks
.as_slice()
.iter()
- .map(|sink| (sink.id, *sink))
+ .map(|sink| (sink.handle, *sink))
.collect();
receiver.image_frames = content
.image_frames
@@ -854,6 +846,11 @@ impl RasterHost {
unsafe { (self.0.apply_resource_changes)(self.host(), context_id.0, changes) };
}
+ pub fn set_drawn_video_sinks(&self, context_id: CompositorContextId, video_sink_handles: &[u64]) {
+ // SAFETY: The host outlives this, and reads the handles during the call.
+ unsafe { (self.0.set_drawn_video_sinks)(self.host(), context_id.0, ak::Span::new(video_sink_handles)) };
+ }
+
pub fn staged_rasterization_has_resources(
&self,
client: u64,