Skip to content

Truly independent web browser

Compositor: Hand the presenter each frame's inputs by value

Aliaksandr Kalenik88514e5cb5a4
diff --git a/Libraries/LibCompositing/Scrolling/ScrollState.h b/Libraries/LibCompositing/Scrolling/ScrollState.h
index 7c26ef26c84..f6210a8b562 100644
--- a/Libraries/LibCompositing/Scrolling/ScrollState.h
+++ b/Libraries/LibCompositing/Scrolling/ScrollState.h
@@ -20,7 +20,7 @@
namespace Compositing {
// The world transforms built for one visual context tree under a snapshot's offsets. A copy starts empty, so the table
-// never outlives the offsets it was built for.
+// never outlives the offsets it was built for. A move takes the table along with the offsets.
class COMPOSITING_API WorldTransformsCache {
public:
WorldTransformsCache() = default;
@@ -30,6 +30,20 @@ public:
clear();
return *this;
}
+ WorldTransformsCache(WorldTransformsCache&& other)
+ : m_retained_tree(exchange(other.m_retained_tree, nullptr))
+ , m_world_transforms(exchange(other.m_world_transforms, nullptr))
+ {
+ }
+ WorldTransformsCache& operator=(WorldTransformsCache&& other)
+ {
+ if (this != &other) {
+ clear();
+ m_retained_tree = exchange(other.m_retained_tree, nullptr);
+ m_world_transforms = exchange(other.m_world_transforms, nullptr);
+ }
+ return *this;
+ }
~WorldTransformsCache() { clear(); }
void const* get_or_build(AccumulatedVisualContextTree const&, ReadonlySpan<Gfx::FloatPoint> device_offsets);
@@ -89,6 +103,14 @@ public:
m_device_offsets.append(offsets.data(), min(offsets.size(), m_node_count));
}
+ // The world transforms another snapshot built are the ones this snapshot would build while both hold the same
+ // offsets, so this one takes them over then instead of building its own.
+ void take_world_transforms_built_for_the_same_offsets_from(ScrollStateSnapshot& other)
+ {
+ if (m_device_offsets == other.m_device_offsets)
+ m_world_transforms_cache = move(other.m_world_transforms_cache);
+ }
+
// Bind the snapshot to the authoritative node count from the AccumulatedVisualContextTree that owns these nodes.
// Wire-decoded offsets are staged rather than densified. So, this is where a decoded index is first validated:
// staged pairs are applied through the bounded setter above, dropping any whose index is at or past the node count.
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index 769891fab1c..92d369b869d 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -269,6 +269,7 @@ void CompositorState::stop_presenting_to_client(Web::CompositorContextId context
VERIFY(context);
unbind_presentation(context_id);
context->stop_presenting_to_client();
+ context->presenter().stop_presenting_to_client();
}
void CompositorState::update_display_list(Web::CompositorContextId context_id, NonnullRefPtr<Compositing::DisplayList> display_list, Compositing::AccumulatedVisualContextTree visual_context_tree, Compositing::DisplayListResourceTransaction&& resource_transaction, Compositing::ScrollStateSnapshot&& scroll_state_snapshot)
@@ -287,7 +288,8 @@ void CompositorState::update_display_list(Web::CompositorContextId context_id, N
return;
}
- context->apply_display_list_resource_transaction(move(resource_transaction));
+ context->presenter().apply_resource_transaction(move(resource_transaction));
+ context->presenter().set_display_list(display_list);
context->install_display_list_update(move(display_list), move(visual_context_tree), move(scroll_state_snapshot));
resolve_video_sinks(*context);
show_animated_image_frames_in(*context);
@@ -299,7 +301,7 @@ void CompositorState::update_display_list_resources(Web::CompositorContextId con
{
auto* context = context_if_present(context_id);
VERIFY(context);
- context->apply_display_list_resource_transaction(move(resource_transaction));
+ context->presenter().apply_resource_transaction(move(resource_transaction));
show_animated_image_frames_in(*context);
}
@@ -308,7 +310,8 @@ void CompositorState::update_visual_context_tree(Web::CompositorContextId contex
auto* context = context_if_present(context_id);
VERIFY(context);
- context->update_visual_context_tree(move(visual_context_tree), move(resource_transaction));
+ if (context->update_visual_context_tree(move(visual_context_tree)))
+ context->presenter().apply_resource_transaction(move(resource_transaction));
show_animated_image_frames_in(*context);
}
@@ -489,7 +492,7 @@ bool CompositorState::animated_image_is_drawn(CompositorStateWebContentClient* c
{
for (auto& context_entry : m_contexts) {
auto& context = *context_entry.value;
- if (&context.web_content_client() == client && context_is_effectively_visible(context) && context.has_image_frame(id))
+ if (&context.web_content_client() == client && context_is_effectively_visible(context) && context.presenter().resource_storage().has_image_frame(id))
return true;
}
return false;
@@ -499,9 +502,9 @@ void CompositorState::show_animated_image_frame(CompositorStateWebContentClient*
{
for (auto& context_entry : m_contexts) {
auto& context = *context_entry.value;
- if (&context.web_content_client() != client || !context.has_image_frame(id))
+ if (&context.web_content_client() != client || !context.presenter().resource_storage().has_image_frame(id))
continue;
- context.replace_image_frame_pixels(id, frame);
+ context.presenter().resource_storage().replace_image_frame_pixels(id, frame);
if (!context_is_effectively_visible(context))
continue;
if (auto rect = context.presenter().self_present_rect(); rect.has_value())
@@ -517,8 +520,8 @@ void CompositorState::show_animated_image_frames_in(ContextState& context)
for (auto& image_entry : images->value) {
Compositing::ImageFrameResourceId id { image_entry.key };
auto const& frame = image_entry.value->shown_frame();
- if (frame.has_value() && context.has_image_frame(id) && &context.image_frame(id).bitmap() != &frame->bitmap())
- context.replace_image_frame_pixels(id, *frame);
+ if (frame.has_value() && context.presenter().resource_storage().has_image_frame(id) && &context.presenter().resource_storage().image_frame(id).bitmap() != &frame->bitmap())
+ context.presenter().resource_storage().replace_image_frame_pixels(id, *frame);
}
// An image that nothing drew has been waiting for a context to draw it.
if (!images->value.is_empty())
@@ -576,7 +579,7 @@ void CompositorState::present_contexts_drawing_video_sink(CompositorStateWebCont
continue;
if (!context_is_effectively_visible(context))
continue;
- for (auto const& resource_entry : context.video_sink_handles()) {
+ for (auto const& resource_entry : context.presenter().resource_storage().video_sink_handles()) {
if (resource_entry.value == handle) {
if (auto rect = context.presenter().self_present_rect(); rect.has_value())
schedule_present_frame(context_entry.key, context, PendingFrame::repainting_changes(*rect));
@@ -602,9 +605,9 @@ void CompositorState::present_contexts_drawing_canvas(CompositorStateWebContentC
void CompositorState::resolve_video_sinks(ContextState& context)
{
auto& client = context.web_content_client();
- for (auto const& resource_entry : context.video_sink_handles()) {
+ for (auto const& resource_entry : context.presenter().resource_storage().video_sink_handles()) {
auto* sink_state = video_sink_state(client, resource_entry.value);
- context.set_video_sink(Compositing::VideoSinkResourceId { resource_entry.key }, sink_state ? sink_state->sink : nullptr);
+ context.presenter().resource_storage().set_video_sink(Compositing::VideoSinkResourceId { resource_entry.key }, sink_state ? sink_state->sink : nullptr);
}
}
@@ -614,7 +617,7 @@ bool CompositorState::video_sink_is_painted_by_any_context(CompositorStateWebCon
auto const& context = *context_entry.value;
if (&context.web_content_client() != client)
continue;
- for (auto const& resource_entry : context.video_sink_handles()) {
+ for (auto const& resource_entry : context.presenter().resource_storage().video_sink_handles()) {
if (resource_entry.value == handle)
return true;
}
@@ -680,7 +683,7 @@ void CompositorState::update_video_sinks_for_display(Optional<u64> display_id)
continue;
if (!context_is_effectively_visible(context))
continue;
- for (auto const& resource_entry : context.video_sink_handles()) {
+ for (auto const& resource_entry : context.presenter().resource_storage().video_sink_handles()) {
auto* sink_state = video_sink_state(context.web_content_client(), resource_entry.value);
if (sink_state != nullptr && sink_state->requires_updates) {
vsync_scheduler_for_display(display_id).schedule(display_refresh_rate_for_context(context));
@@ -875,7 +878,7 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId c
// The content box of a nested context is drawn scaled to the size of its viewport.
static Optional<Gfx::FloatPoint> position_in_nested_context(Compositing::NestedContextHit const& hit, ContextState const& nested_context)
{
- auto viewport_size = nested_context.presenter().viewport_size().to_type<float>();
+ auto viewport_size = nested_context.viewport_size().to_type<float>();
if (hit.content_box_size.is_empty() || viewport_size.is_empty())
return {};
return Gfx::FloatPoint {
@@ -1290,7 +1293,7 @@ CompositorState::AppliedWheelStep CompositorState::route_wheel_step_the_page_let
auto* parent_context = parent_context_id.has_value() ? context_if_present(*parent_context_id) : nullptr;
if (!parent_context)
return declined(Web::InputRoutingDecision::NestedContextUnavailable);
- auto position = parent_context->position_of_nested_context_position(context_id, step.position, context->presenter().viewport_size());
+ auto position = parent_context->position_of_nested_context_position(context_id, step.position, context->viewport_size());
if (!position.has_value())
return declined(Web::InputRoutingDecision::NestedContextUnavailable);
step.position = *position;
@@ -1536,7 +1539,9 @@ void CompositorState::viewport_size_updated(Web::CompositorContextId context_id,
return;
auto only_the_pixel_ratio_changed = viewport_size == context->presenter().viewport_size() && device_pixel_ratio != context->presenter().device_pixel_ratio();
- context->viewport_size_updated(viewport_size, device_pixel_ratio, window_resize_in_progress);
+ context->viewport_size_updated(viewport_size);
+ auto is_page_presentation_context = context->page_id().has_value() && !context->parent_context_id().has_value();
+ context->presenter().set_viewport_size(viewport_size, device_pixel_ratio, is_page_presentation_context ? window_resize_in_progress : Compositing::WindowResizingInProgress::No);
resize_backing_stores_if_needed(context_id, *context);
// The paused debugger's page will not paint again. Any other page's next frame damages the whole viewport when its
@@ -1555,8 +1560,10 @@ void CompositorState::set_ui_overlays(Web::CompositorContextId context_id, Compo
auto* context = context_if_present(context_id);
if (!context)
return;
- if (!context->set_ui_overlays(move(overlays)))
+ if (context->presenter().ui_overlays() == overlays)
return;
+ context->set_paused_debugger_overlay_is_shown(overlays.paused_debugger.has_value());
+ context->presenter().set_ui_overlays(move(overlays));
if (auto viewport_rect = context->presenter().viewport_rect_for_ui_overlay(); viewport_rect.has_value())
schedule_present_frame(context_id, *context, *viewport_rect);
@@ -1572,7 +1579,8 @@ void CompositorState::set_display_metadata(Web::CompositorContextId context_id,
VERIFY(refresh_rate > 0);
VERIFY(refresh_rate < AK::Infinity<double>);
- if (context->set_display_metadata(display_id, refresh_rate)) {
+ context->set_display_metadata(display_id, refresh_rate);
+ if (context->presenter().pending_present_frame_scheduled()) {
schedule_pending_present_frame(context_id, *context);
if (m_unpainted_video_update_timer)
m_unpainted_video_update_timer->set_interval(AK::Duration::from_milliseconds(unpainted_video_update_interval_ms()));
@@ -1691,7 +1699,7 @@ void CompositorState::present_frame(Web::CompositorContextId context_id, Gfx::In
void CompositorState::present_frame(Web::CompositorContextId context_id, ContextState& context, PendingFrame pending_frame)
{
auto composited_context_resolver = resolver_for(context_id);
- auto prepared_frame = context.prepare_frame(*m_display_list_player, pending_frame, &composited_context_resolver);
+ auto prepared_frame = context.presenter().prepare_frame(*m_display_list_player, pending_frame, context.frame_inputs(), &composited_context_resolver);
if (!prepared_frame.has_value())
return;
@@ -1754,9 +1762,19 @@ void CompositorState::schedule_pending_present_frame(Web::CompositorContextId co
schedule_pending_present_frame_on_vsync(context_id, context);
}
+static bool needs_animation_frames(ContextState& context)
+{
+ return context.needs_animation_frames() || context.presenter().ui_overlay_fades_need_frame();
+}
+
+static bool has_pending_present_frame_scheduled_on(ContextState const& context, Optional<u64> display_id)
+{
+ return context.presenter().pending_present_frame_scheduled() && context.display_id() == display_id;
+}
+
void CompositorState::schedule_animation_frames_if_needed(ContextState& context)
{
- if (context.needs_animation_frames() && context_is_effectively_visible(context))
+ if (needs_animation_frames(context) && context_is_effectively_visible(context))
vsync_scheduler_for_display(display_id_for_context(context)).schedule(display_refresh_rate_for_context(context));
}
@@ -1848,8 +1866,8 @@ void CompositorState::present_pending_frames_on_vsync(Optional<u64> display_id,
}
}
- auto has_active_animation_on_display = context.needs_animation_frames() && display_id_for_context(context) == display_id;
- auto presents_on_display = context.has_pending_present_frame_scheduled_on(display_id) || has_active_animation_on_display;
+ auto has_active_animation_on_display = needs_animation_frames(context) && display_id_for_context(context) == display_id;
+ auto presents_on_display = has_pending_present_frame_scheduled_on(context, display_id) || has_active_animation_on_display;
if (presents_on_display) {
if (display_id_for_context(context) == display_id)
dispatch_scroll_fling_step(context_id, context, context.take_scroll_fling_step(frame_time), frame_time);
@@ -1859,8 +1877,10 @@ void CompositorState::present_pending_frames_on_vsync(Optional<u64> display_id,
context.presenter().queue_present_frame(PendingFrame::repainting_changes(*rebound_frame));
if (auto fade_frame = context.presenter().advance_ui_overlay_fades(frame_time); fade_frame.has_value())
context.presenter().queue_present_frame(*fade_frame);
- if (auto fade_frame = context.advance_scrollbar_fades(frame_time); fade_frame.has_value())
- context.presenter().queue_present_frame(*fade_frame);
+ if (auto damage_rect = context.advance_scrollbar_fades_and_return_damage_rect(frame_time); !damage_rect.is_empty()) {
+ if (auto viewport_rect = context.presenter().viewport_rect_for_ui_overlay(); viewport_rect.has_value())
+ context.presenter().queue_present_frame({ *viewport_rect, damage_rect });
+ }
}
// A render clock tick goes to the process's render clock thread, beside what its main thread is doing, with
@@ -1889,12 +1909,12 @@ void CompositorState::present_pending_frames_on_vsync(Optional<u64> display_id,
add_backing_store_for_pending_frame_if_needed(context_id, context);
auto pending_present_frame = context.presenter().take_pending_present_frame_if_unblocked();
if (!pending_present_frame.has_value()) {
- has_active_animation_on_display = context.needs_animation_frames() && display_id_for_context(context) == display_id;
- if (context.has_pending_present_frame_scheduled_on(display_id) || has_active_animation_on_display)
+ has_active_animation_on_display = needs_animation_frames(context) && display_id_for_context(context) == display_id;
+ if (has_pending_present_frame_scheduled_on(context, display_id) || has_active_animation_on_display)
vsync_scheduler_for_display(display_id).schedule(display_refresh_rate_for_context(context));
continue;
}
- if (context.needs_animation_frames())
+ if (needs_animation_frames(context))
schedule_present_frame(context_id, context, PendingFrame::repainting_changes(pending_present_frame->viewport_rect));
present_frame(context_id, context, *pending_present_frame);
}
@@ -1905,12 +1925,16 @@ bool CompositorState::request_screenshot(Web::CompositorContextId context_id, Gf
auto* context = context_if_present(context_id);
VERIFY(context);
- if (!context->can_paint_screenshot(target_bitmap))
+ if (!context->presenter().has_display_list() || !target_bitmap.is_valid() || !target_bitmap.bitmap())
return false;
auto composited_context_resolver = resolver_for(context_id);
- if (auto scrollbar_fade_frame = context->paint_screenshot(*m_display_list_player, target_bitmap, &composited_context_resolver); scrollbar_fade_frame.has_value())
- schedule_present_frame(context_id, *context, *scrollbar_fade_frame);
+ auto screenshot_inputs = context->frame_inputs_for_screenshot();
+ context->presenter().paint_screenshot(*m_display_list_player, target_bitmap, screenshot_inputs.frame_inputs, &composited_context_resolver);
+ if (!screenshot_inputs.scrollbar_fade_damage_rect.is_empty()) {
+ if (auto viewport_rect = context->presenter().viewport_rect_for_ui_overlay(); viewport_rect.has_value())
+ schedule_present_frame(context_id, *context, { *viewport_rect, screenshot_inputs.scrollbar_fade_damage_rect });
+ }
return true;
}
@@ -2074,7 +2098,7 @@ CompositedContextSurface CompositorState::resolve_composited_context(Web::Compos
if (child_context->presenter().needs_rasterization()) {
auto composited_context_resolver = resolver_for(child_context_id);
DisplayListPlayerSkia display_list_player { m_skia_backend_context };
- child_context->present_synchronously(display_list_player, &composited_context_resolver);
+ child_context->presenter().present_synchronously(display_list_player, child_context->frame_inputs(), &composited_context_resolver);
}
return child_context->presenter().composited_surface();
diff --git a/Services/Compositor/ContextPresenter.cpp b/Services/Compositor/ContextPresenter.cpp
index 80946b91f3b..ffb6eee83ff 100644
--- a/Services/Compositor/ContextPresenter.cpp
+++ b/Services/Compositor/ContextPresenter.cpp
@@ -7,7 +7,6 @@
#include <AK/Math.h>
#include <Compositor/CanvasSurfaceRegistry.h>
#include <Compositor/ContextPresenter.h>
-#include <Compositor/ContextScene.h>
#include <Compositor/DisplayListPlayerSkia.h>
#include <Compositor/PausedDebuggerOverlay.h>
#include <Compositor/PictureInPictureControls.h>
@@ -43,9 +42,8 @@ static Gfx::FloatSize bounded_composited_raster_scale(Gfx::FloatSize scale, Gfx:
return scale;
}
-ContextPresenter::ContextPresenter(ContextScene& scene, OwnedCanvasSurfaces canvas_surfaces, bool presents_to_client)
- : m_scene(scene)
- , m_canvas_surfaces(canvas_surfaces)
+ContextPresenter::ContextPresenter(OwnedCanvasSurfaces canvas_surfaces, bool presents_to_client)
+ : m_canvas_surfaces(canvas_surfaces)
, m_presents_to_client(presents_to_client)
{
}
@@ -56,6 +54,16 @@ ContextPresenter::~ContextPresenter()
stop_surplus_backing_store_retirement_timer();
}
+void ContextPresenter::set_display_list(NonnullRefPtr<Compositing::DisplayList const> display_list)
+{
+ m_display_list = move(display_list);
+}
+
+void ContextPresenter::apply_resource_transaction(Compositing::DisplayListResourceTransaction&& resource_transaction)
+{
+ m_raster_cache.evict(m_resource_storage.apply_transaction(move(resource_transaction)));
+}
+
void ContextPresenter::set_viewport_size(Gfx::IntSize viewport_size, double device_pixel_ratio, Compositing::WindowResizingInProgress window_resize_in_progress)
{
m_viewport_size = viewport_size;
@@ -291,7 +299,7 @@ bool ContextPresenter::draws_canvas(Compositing::CanvasId canvas_id) const
return m_last_rasterized_frame.has_value() && m_last_rasterized_frame->canvas_content_generations.contains(canvas_id);
}
-Optional<PreparedFrame> ContextPresenter::prepare_frame(DisplayListPlayerSkia& display_list_player, PendingFrame pending_frame, FrameContent const& frame_content)
+Optional<PreparedFrame> ContextPresenter::prepare_frame(DisplayListPlayerSkia& display_list_player, PendingFrame pending_frame, Optional<FrameInputs>&& frame_inputs, CompositedContextResolver const* composited_context_resolver)
{
if (is_present_blocked()) {
queue_present_frame(pending_frame);
@@ -302,11 +310,13 @@ Optional<PreparedFrame> ContextPresenter::prepare_frame(DisplayListPlayerSkia& d
m_presented_frame = pending_frame.viewport_rect;
return {};
}
+ VERIFY(frame_inputs.has_value());
- auto damage_rect = frame_damage_for(pending_frame, frame_content);
+ auto damage_rect = frame_damage_for(pending_frame, *frame_inputs);
+ keep_world_transforms_of_last_rasterized_frame(*frame_inputs);
// NB: A changed content rect must still reach the client even if the pixels are identical.
if (damage_rect.is_empty() && m_presented_frame == pending_frame.viewport_rect) {
- remember_rasterized_frame(pending_frame.viewport_rect.size(), frame_content.presented_scroll_state_snapshot);
+ remember_rasterized_frame(pending_frame.viewport_rect.size(), frame_inputs.release_value());
return {};
}
auto render_target = m_backing_store_manager.acquire_render_target(raster_damage_rect(damage_rect));
@@ -315,8 +325,8 @@ Optional<PreparedFrame> ContextPresenter::prepare_frame(DisplayListPlayerSkia& d
return {};
}
auto& back_store = render_target->surface;
- paint_current_display_list(display_list_player, back_store, frame_content, render_target->damage_rect);
- remember_rasterized_frame(pending_frame.viewport_rect.size(), frame_content.presented_scroll_state_snapshot);
+ paint_current_display_list(display_list_player, back_store, *frame_inputs, composited_context_resolver, render_target->damage_rect);
+ remember_rasterized_frame(pending_frame.viewport_rect.size(), frame_inputs.release_value());
return PreparedFrame {
.rendered_surface = &back_store,
@@ -331,10 +341,11 @@ void ContextPresenter::did_submit_prepared_frame(Gfx::IntRect viewport_rect)
m_presented_frame = viewport_rect;
}
-bool ContextPresenter::present_synchronously(DisplayListPlayerSkia& display_list_player, FrameContent const& frame_content)
+bool ContextPresenter::present_synchronously(DisplayListPlayerSkia& display_list_player, Optional<FrameInputs>&& frame_inputs, CompositedContextResolver const* composited_context_resolver)
{
if (!can_render_frame())
return false;
+ VERIFY(frame_inputs.has_value());
// Don't race an async present already in flight for this context; its own completion will update the output.
if (is_present_blocked())
return false;
@@ -345,12 +356,13 @@ bool ContextPresenter::present_synchronously(DisplayListPlayerSkia& display_list
if (!pending_frame.has_value())
return false;
- auto render_target = m_backing_store_manager.acquire_render_target(raster_damage_rect(frame_damage_for(*pending_frame, frame_content)));
+ auto render_target = m_backing_store_manager.acquire_render_target(raster_damage_rect(frame_damage_for(*pending_frame, *frame_inputs)));
if (!render_target.has_value())
return false;
+ keep_world_transforms_of_last_rasterized_frame(*frame_inputs);
auto& back_store = render_target->surface;
- paint_current_display_list(display_list_player, back_store, frame_content, render_target->damage_rect);
- remember_rasterized_frame(pending_frame->viewport_rect.size(), frame_content.presented_scroll_state_snapshot);
+ paint_current_display_list(display_list_player, back_store, *frame_inputs, composited_context_resolver, render_target->damage_rect);
+ remember_rasterized_frame(pending_frame->viewport_rect.size(), frame_inputs.release_value());
display_list_player.flush(back_store);
m_backing_store_manager.complete_rendering(render_target->bitmap_id, false);
m_latest_rendered_surface = m_backing_store_manager.latest_rendered_surface();
@@ -360,10 +372,10 @@ bool ContextPresenter::present_synchronously(DisplayListPlayerSkia& display_list
return true;
}
-void ContextPresenter::paint_screenshot(DisplayListPlayerSkia& display_list_player, Gfx::ShareableBitmap& target_bitmap, FrameContent const& frame_content)
+void ContextPresenter::paint_screenshot(DisplayListPlayerSkia& display_list_player, Gfx::ShareableBitmap& target_bitmap, FrameInputs const& frame_inputs, CompositedContextResolver const* composited_context_resolver)
{
auto target_surface = Gfx::PaintingSurface::wrap_bitmap(*target_bitmap.bitmap());
- paint_current_display_list(display_list_player, *target_surface, frame_content, {}, PaintUIOverlay::No, false);
+ paint_current_display_list(display_list_player, *target_surface, frame_inputs, composited_context_resolver, {}, PaintUIOverlay::No, false);
display_list_player.flush(*target_surface);
}
@@ -391,7 +403,7 @@ bool ContextPresenter::is_present_blocked() const
bool ContextPresenter::can_render_frame() const
{
- return m_scene.display_list() && m_backing_store_manager.is_valid();
+ return m_display_list && m_backing_store_manager.is_valid();
}
Gfx::IntSize ContextPresenter::raster_size() const
@@ -418,27 +430,27 @@ Gfx::IntRect ContextPresenter::raster_damage_rect(Gfx::IntRect damage_rect) cons
return Gfx::enclosing_int_rect(rect).intersected(Gfx::IntRect { {}, raster_size() });
}
-Gfx::IntRect ContextPresenter::frame_damage_for(PendingFrame const& pending_frame, FrameContent const& frame_content)
+Gfx::IntRect ContextPresenter::frame_damage_for(PendingFrame const& pending_frame, FrameInputs const& frame_inputs)
{
Gfx::IntRect viewport_rect { {}, pending_frame.viewport_rect.size() };
auto forced_damage_rect = pending_frame.forced_damage_rect.intersected(viewport_rect);
if (forced_damage_rect.contains(viewport_rect))
return viewport_rect;
- return damage_since_last_raster(viewport_rect.size(), frame_content, forced_damage_rect);
+ return damage_since_last_raster(viewport_rect.size(), frame_inputs, forced_damage_rect);
}
-Gfx::IntRect ContextPresenter::damage_since_last_raster(Gfx::IntSize viewport_size, FrameContent const& frame_content, Gfx::IntRect forced_damage_rect)
+Gfx::IntRect ContextPresenter::damage_since_last_raster(Gfx::IntSize viewport_size, FrameInputs const& frame_inputs, Gfx::IntRect forced_damage_rect)
{
- auto const& presented_scroll_state_snapshot = frame_content.presented_scroll_state_snapshot;
+ auto const& presented_scroll_state_snapshot = frame_inputs.presented_scroll_state_snapshot;
Gfx::IntRect viewport_rect { {}, viewport_size };
if (!m_last_rasterized_frame.has_value())
return viewport_rect;
auto const& last_frame = *m_last_rasterized_frame;
if (last_frame.viewport_size != viewport_size)
return viewport_rect;
- if (last_frame.display_list->surface_clear_color() != m_scene.display_list()->surface_clear_color())
+ if (last_frame.display_list->surface_clear_color() != m_display_list->surface_clear_color())
return viewport_rect;
- if (auto index = frame_content.viewport_scroll_node_index; index.has_value()) {
+ if (auto index = frame_inputs.viewport_scroll_node_index; index.has_value()) {
if (last_frame.scroll_state_snapshot.device_offset_for_index(*index) != presented_scroll_state_snapshot.device_offset_for_index(*index))
return viewport_rect;
}
@@ -449,7 +461,7 @@ Gfx::IntRect ContextPresenter::damage_since_last_raster(Gfx::IntSize viewport_si
canvases_with_new_content.append(canvas_id);
}
Vector<Compositing::VideoSinkResourceId> video_sinks_with_new_frames;
- auto video_sinks_drawn_by_list = m_scene.display_list()->referenced_resource_ids().video_sinks;
+ auto video_sinks_drawn_by_list = m_display_list->referenced_resource_ids().video_sinks;
for (auto const& [video_sink_id, frame_id] : last_frame.video_frame_ids) {
if (current_video_frame_id(video_sink_id) == frame_id)
continue;
@@ -460,8 +472,8 @@ Gfx::IntRect ContextPresenter::damage_since_last_raster(Gfx::IntSize viewport_si
video_sinks_with_new_frames.append(video_sink_id);
}
Vector<Compositing::ImageFrameResourceId> image_frames_with_new_pixels;
- auto image_frames_drawn_by_list = m_scene.display_list()->referenced_resource_ids().image_frames;
- for (auto const& [image_frame_id, generation] : m_scene.resource_storage().image_frame_pixel_generations()) {
+ auto image_frames_drawn_by_list = m_display_list->referenced_resource_ids().image_frames;
+ for (auto const& [image_frame_id, generation] : m_resource_storage.image_frame_pixel_generations()) {
if (last_frame.image_frame_pixel_generations.get(image_frame_id) == generation)
continue;
// An image drawn only by a nested display list, such as an SVG image's, has no command in this list to damage.
@@ -469,19 +481,19 @@ Gfx::IntRect ContextPresenter::damage_since_last_raster(Gfx::IntSize viewport_si
return viewport_rect;
image_frames_with_new_pixels.append(Compositing::ImageFrameResourceId { image_frame_id });
}
- for (auto const& scrollbar : frame_content.scrollbar_controller.scrollbars()) {
+ for (auto const& scrollbar : frame_inputs.scrollbars) {
if (!scrollbar.is_painted_by_compositor)
continue;
if (last_frame.scroll_state_snapshot.device_offset_for_index(scrollbar.scroll_node_index) == presented_scroll_state_snapshot.device_offset_for_index(scrollbar.scroll_node_index))
continue;
- forced_damage_rect.unite(scrollbar.gutter_rect.united(scrollbar.expanded_gutter_rect));
+ forced_damage_rect.unite(scrollbar.thin_and_expanded_gutter_rect);
}
auto display_list_damage = Compositing::compute_display_list_damage(
*last_frame.display_list,
last_frame.visual_context_tree,
last_frame.scroll_state_snapshot,
- *m_scene.display_list(),
- m_scene.visual_context_tree_for_compositing(),
+ *m_display_list,
+ frame_inputs.visual_context_tree,
presented_scroll_state_snapshot,
viewport_rect,
{ .canvases = canvases_with_new_content, .video_sinks = video_sinks_with_new_frames, .image_frames = image_frames_with_new_pixels, .forced_damage_rect = forced_damage_rect });
@@ -490,33 +502,39 @@ Gfx::IntRect ContextPresenter::damage_since_last_raster(Gfx::IntSize viewport_si
return display_list_damage->intersected(viewport_rect);
}
-void ContextPresenter::remember_rasterized_frame(Gfx::IntSize viewport_size, Compositing::ScrollStateSnapshot const& presented_scroll_state_snapshot)
+void ContextPresenter::keep_world_transforms_of_last_rasterized_frame(FrameInputs& frame_inputs)
+{
+ if (m_last_rasterized_frame.has_value())
+ frame_inputs.presented_scroll_state_snapshot.take_world_transforms_built_for_the_same_offsets_from(m_last_rasterized_frame->scroll_state_snapshot);
+}
+
+void ContextPresenter::remember_rasterized_frame(Gfx::IntSize viewport_size, FrameInputs&& frame_inputs)
{
HashMap<Compositing::CanvasId, u64> canvas_content_generations;
- for (auto id : m_scene.display_list()->referenced_resource_ids().canvases) {
+ for (auto id : m_display_list->referenced_resource_ids().canvases) {
Compositing::CanvasId canvas_id { id };
canvas_content_generations.set(canvas_id, m_canvas_surfaces.canvas_content_generation(canvas_id));
}
// Every video the context holds is drawn by the list or by a display list it nests.
HashMap<Compositing::VideoSinkResourceId, Optional<u64>> video_frame_ids;
- for (auto const& [id, handle] : m_scene.video_sink_handles()) {
+ for (auto const& [id, handle] : m_resource_storage.video_sink_handles()) {
Compositing::VideoSinkResourceId video_sink_id { id };
video_frame_ids.set(video_sink_id, current_video_frame_id(video_sink_id));
}
m_last_rasterized_frame = RasterizedFrame {
- .display_list = NonnullRefPtr { *m_scene.display_list() },
- .visual_context_tree = m_scene.visual_context_tree_for_compositing(),
- .scroll_state_snapshot = presented_scroll_state_snapshot,
+ .display_list = NonnullRefPtr { *m_display_list },
+ .visual_context_tree = move(frame_inputs.visual_context_tree),
+ .scroll_state_snapshot = move(frame_inputs.presented_scroll_state_snapshot),
.viewport_size = viewport_size,
.canvas_content_generations = move(canvas_content_generations),
.video_frame_ids = move(video_frame_ids),
- .image_frame_pixel_generations = m_scene.resource_storage().image_frame_pixel_generations(),
+ .image_frame_pixel_generations = m_resource_storage.image_frame_pixel_generations(),
};
}
Optional<u64> ContextPresenter::current_video_frame_id(Compositing::VideoSinkResourceId video_sink_id)
{
- auto sink = m_scene.resource_storage().video_sink(video_sink_id);
+ auto sink = m_resource_storage.video_sink(video_sink_id);
if (!sink)
return {};
auto frame = sink->current_frame();
@@ -525,22 +543,22 @@ Optional<u64> ContextPresenter::current_video_frame_id(Compositing::VideoSinkRes
return frame->id();
}
-void ContextPresenter::paint_current_display_list(DisplayListPlayerSkia& display_list_player, Gfx::PaintingSurface& surface, FrameContent const& frame_content, Optional<Gfx::IntRect> damage_rect, PaintUIOverlay paint_ui_overlay, bool apply_raster_transform)
+void ContextPresenter::paint_current_display_list(DisplayListPlayerSkia& display_list_player, Gfx::PaintingSurface& surface, FrameInputs const& frame_inputs, CompositedContextResolver const* composited_context_resolver, Optional<Gfx::IntRect> damage_rect, PaintUIOverlay paint_ui_overlay, bool apply_raster_transform)
{
- VERIFY(m_scene.display_list());
- auto surface_clear_color = Gfx::to_skia_color(m_scene.display_list()->surface_clear_color().value_or(Gfx::Color::Transparent));
+ VERIFY(m_display_list);
+ auto surface_clear_color = Gfx::to_skia_color(m_display_list->surface_clear_color().value_or(Gfx::Color::Transparent));
auto paint_display_list = [&](Gfx::PaintingSurface& target_surface) {
display_list_player.execute(
- *m_scene.display_list(),
- m_scene.visual_context_tree_for_compositing(),
- m_scene.resource_storage(),
- m_scene.raster_cache(),
- frame_content.presented_scroll_state_snapshot,
+ *m_display_list,
+ frame_inputs.visual_context_tree,
+ m_resource_storage,
+ m_raster_cache,
+ frame_inputs.presented_scroll_state_snapshot,
target_surface,
&m_canvas_surfaces,
- frame_content.composited_context_resolver,
- &frame_content.scrollbar_controller);
- frame_content.scrollbar_controller.paint(target_surface, display_list_player, frame_content.presented_scroll_state_snapshot);
+ composited_context_resolver,
+ frame_inputs.scrollbars);
+ display_list_player.paint_scrollbars_painted_by_compositor(target_surface, frame_inputs.scrollbars);
if (paint_ui_overlay == PaintUIOverlay::No)
return;
diff --git a/Services/Compositor/ContextPresenter.h b/Services/Compositor/ContextPresenter.h
index 417741fa43e..cc853c1011a 100644
--- a/Services/Compositor/ContextPresenter.h
+++ b/Services/Compositor/ContextPresenter.h
@@ -16,10 +16,13 @@
#include <Compositor/BackingStoreManager.h>
#include <Compositor/CanvasSurfaceRegistry.h>
#include <Compositor/CompositedContext.h>
+#include <Compositor/DisplayListRasterCache.h>
#include <Compositor/Forward.h>
#include <Compositor/PaintingSurface.h>
+#include <Compositor/ScrollbarController.h>
#include <LibCompositing/DisplayList/AccumulatedVisualContext.h>
#include <LibCompositing/DisplayList/DisplayList.h>
+#include <LibCompositing/DisplayList/DisplayListResourceStorage.h>
#include <LibCompositing/Forward.h>
#include <LibCompositing/OverlayFade.h>
#include <LibCompositing/Scrolling/ScrollState.h>
@@ -39,9 +42,6 @@ class SkiaBackendContext;
namespace Compositor {
-class ContextScene;
-class ScrollbarController;
-
struct PendingFrame {
Gfx::IntRect viewport_rect;
Gfx::IntRect forced_damage_rect;
@@ -57,23 +57,29 @@ struct PreparedFrame {
double device_pixel_ratio { 1.0 };
};
+// What a frame is painted with besides the display list and its resources.
+struct FrameInputs {
+ Compositing::AccumulatedVisualContextTree visual_context_tree;
+ Compositing::ScrollStateSnapshot presented_scroll_state_snapshot;
+ Vector<ScrollbarController::ScrollbarOfFrame> scrollbars;
+ Optional<Compositing::SpatialNodeIndex> viewport_scroll_node_index;
+};
+
// Rasterizes the scene of a context into its backing stores and keeps track of the frames it presents.
class ContextPresenter {
AK_MAKE_NONCOPYABLE(ContextPresenter);
AK_MAKE_NONMOVABLE(ContextPresenter);
public:
- // What a frame is painted with besides the scene.
- struct FrameContent {
- Compositing::ScrollStateSnapshot const& presented_scroll_state_snapshot;
- ScrollbarController const& scrollbar_controller;
- Optional<Compositing::SpatialNodeIndex> viewport_scroll_node_index;
- CompositedContextResolver const* composited_context_resolver { nullptr };
- };
-
- ContextPresenter(ContextScene&, OwnedCanvasSurfaces, bool presents_to_client);
+ ContextPresenter(OwnedCanvasSurfaces, bool presents_to_client);
~ContextPresenter();
+ bool has_display_list() const { return m_display_list; }
+ void set_display_list(NonnullRefPtr<Compositing::DisplayList const>);
+ Compositing::DisplayListResourceStorage& resource_storage() { return m_resource_storage; }
+ Compositing::DisplayListResourceStorage const& resource_storage() const { return m_resource_storage; }
+ void apply_resource_transaction(Compositing::DisplayListResourceTransaction&&);
+
bool presents_to_client() const { return m_presents_to_client; }
void stop_presenting_to_client() { m_presents_to_client = false; }
@@ -116,10 +122,11 @@ public:
Optional<Gfx::IntRect> self_present_rect() const;
bool draws_canvas(Compositing::CanvasId) const;
- Optional<PreparedFrame> prepare_frame(DisplayListPlayerSkia&, PendingFrame, FrameContent const&);
+ // The inputs are empty for a context that has no display list yet.
+ Optional<PreparedFrame> prepare_frame(DisplayListPlayerSkia&, PendingFrame, Optional<FrameInputs>&&, CompositedContextResolver const*);
void did_submit_prepared_frame(Gfx::IntRect);
- bool present_synchronously(DisplayListPlayerSkia&, FrameContent const&);
- void paint_screenshot(DisplayListPlayerSkia&, Gfx::ShareableBitmap&, FrameContent const&);
+ bool present_synchronously(DisplayListPlayerSkia&, Optional<FrameInputs>&&, CompositedContextResolver const*);
+ void paint_screenshot(DisplayListPlayerSkia&, Gfx::ShareableBitmap&, FrameInputs const&, CompositedContextResolver const*);
private:
struct RasterizedFrame {
@@ -139,17 +146,20 @@ private:
bool is_present_blocked() const;
bool can_render_frame() const;
- void paint_current_display_list(DisplayListPlayerSkia&, Gfx::PaintingSurface&, FrameContent const&, Optional<Gfx::IntRect> damage_rect = {}, PaintUIOverlay = PaintUIOverlay::Yes, bool apply_raster_transform = true);
+ void paint_current_display_list(DisplayListPlayerSkia&, Gfx::PaintingSurface&, FrameInputs const&, CompositedContextResolver const*, Optional<Gfx::IntRect> damage_rect = {}, PaintUIOverlay = PaintUIOverlay::Yes, bool apply_raster_transform = true);
Gfx::IntSize raster_size() const;
Gfx::IntRect raster_damage_rect(Gfx::IntRect) const;
- Gfx::IntRect frame_damage_for(PendingFrame const&, FrameContent const&);
- Gfx::IntRect damage_since_last_raster(Gfx::IntSize viewport_size, FrameContent const&, Gfx::IntRect forced_damage_rect);
- void remember_rasterized_frame(Gfx::IntSize viewport_size, Compositing::ScrollStateSnapshot const& presented_scroll_state_snapshot);
+ Gfx::IntRect frame_damage_for(PendingFrame const&, FrameInputs const&);
+ Gfx::IntRect damage_since_last_raster(Gfx::IntSize viewport_size, FrameInputs const&, Gfx::IntRect forced_damage_rect);
+ void keep_world_transforms_of_last_rasterized_frame(FrameInputs&);
+ void remember_rasterized_frame(Gfx::IntSize viewport_size, FrameInputs&&);
Optional<u64> current_video_frame_id(Compositing::VideoSinkResourceId);
void stop_backing_store_shrink_timer();
void stop_surplus_backing_store_retirement_timer();
- ContextScene& m_scene;
+ RefPtr<Compositing::DisplayList const> m_display_list;
+ Compositing::DisplayListResourceStorage m_resource_storage;
+ DisplayListRasterCache m_raster_cache;
OwnedCanvasSurfaces m_canvas_surfaces;
bool m_presents_to_client { false };
diff --git a/Services/Compositor/ContextScene.cpp b/Services/Compositor/ContextScene.cpp
index 112e503486a..a102b9fdfc1 100644
--- a/Services/Compositor/ContextScene.cpp
+++ b/Services/Compositor/ContextScene.cpp
@@ -29,7 +29,7 @@ void ContextScene::install(NonnullRefPtr<Compositing::DisplayList> display_list,
update_visual_animation_sampling_state(*m_visual_context_tree, m_visual_animation_sample_time_ns, m_has_active_visual_animations);
}
-bool ContextScene::replace_visual_context_tree(Compositing::AccumulatedVisualContextTree visual_context_tree, Compositing::DisplayListResourceTransaction&& resource_transaction)
+bool ContextScene::replace_visual_context_tree(Compositing::AccumulatedVisualContextTree visual_context_tree)
{
if (!m_display_list || m_display_list->compatible_visual_context_tree_structural_epoch() != visual_context_tree.structural_epoch()) {
dbgln("Compositor: Dropping stale visual context tree update (tree epoch {}, display list epoch {})",
@@ -38,22 +38,11 @@ bool ContextScene::replace_visual_context_tree(Compositing::AccumulatedVisualCon
return false;
}
invalidate_visual_context_tree_for_compositing();
- apply_resource_transaction(move(resource_transaction));
m_visual_context_tree = move(visual_context_tree);
update_visual_animation_sampling_state(*m_visual_context_tree, m_visual_animation_sample_time_ns, m_has_active_visual_animations);
return true;
}
-void ContextScene::apply_resource_transaction(Compositing::DisplayListResourceTransaction&& resource_transaction)
-{
- m_raster_cache.evict(m_resource_storage.apply_transaction(move(resource_transaction)));
-}
-
-void ContextScene::set_video_sink(Compositing::VideoSinkResourceId frame_id, RefPtr<Media::DisplayingVideoSink> sink)
-{
- m_resource_storage.set_video_sink(frame_id, move(sink));
-}
-
Compositing::AccumulatedVisualContextTree const& ContextScene::current_visual_context_tree() const
{
VERIFY(m_display_list);
diff --git a/Services/Compositor/ContextScene.h b/Services/Compositor/ContextScene.h
index 8826dd3dd72..9cf3f28434f 100644
--- a/Services/Compositor/ContextScene.h
+++ b/Services/Compositor/ContextScene.h
@@ -6,20 +6,16 @@
#pragma once
-#include <AK/HashMap.h>
#include <AK/Noncopyable.h>
#include <AK/NonnullRefPtr.h>
#include <AK/Optional.h>
#include <AK/RefPtr.h>
#include <AK/Time.h>
-#include <Compositor/DisplayListRasterCache.h>
#include <LibCompositing/DisplayList/AccumulatedVisualContext.h>
#include <LibCompositing/DisplayList/DisplayList.h>
-#include <LibCompositing/DisplayList/DisplayListResourceStorage.h>
#include <LibCompositing/Forward.h>
#include <LibCompositing/Scrolling/ScrollState.h>
#include <LibGfx/Size.h>
-#include <LibMedia/Forward.h>
namespace Compositor {
@@ -34,17 +30,12 @@ public:
void install(NonnullRefPtr<Compositing::DisplayList>, Compositing::AccumulatedVisualContextTree);
// Returns false, leaving everything as it was, for a tree that does not fit the installed display list.
- bool replace_visual_context_tree(Compositing::AccumulatedVisualContextTree, Compositing::DisplayListResourceTransaction&&);
- void apply_resource_transaction(Compositing::DisplayListResourceTransaction&&);
- void set_video_sink(Compositing::VideoSinkResourceId, RefPtr<Media::DisplayingVideoSink>);
- HashMap<u64, Media::VideoSinkHandle> const& video_sink_handles() const { return m_resource_storage.video_sink_handles(); }
+ bool replace_visual_context_tree(Compositing::AccumulatedVisualContextTree);
RefPtr<Compositing::DisplayList const> const& display_list() const { return m_display_list; }
Optional<Compositing::AccumulatedVisualContextTree> const& visual_context_tree() const { return m_visual_context_tree; }
Compositing::AccumulatedVisualContextTree const& current_visual_context_tree() const;
Compositing::AccumulatedVisualContextTree const& visual_context_tree_for_compositing();
- Compositing::DisplayListResourceStorage& resource_storage() { return m_resource_storage; }
- DisplayListRasterCache& raster_cache() { return m_raster_cache; }
Compositing::TransformWithOrigin visual_viewport_transform() const;
Optional<float> visual_viewport_scale() const;
@@ -70,8 +61,6 @@ private:
Optional<i64> m_visual_animation_sample_time_ns;
bool m_has_active_visual_animations { false };
Optional<bool> m_animated_content_may_affect_viewport;
- Compositing::DisplayListResourceStorage m_resource_storage;
- DisplayListRasterCache m_raster_cache;
};
}
diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cpp
index 166a6e3285c..f6adba9ed69 100644
--- a/Services/Compositor/ContextState.cpp
+++ b/Services/Compositor/ContextState.cpp
@@ -63,7 +63,8 @@ ContextState::ContextState(Web::CompositorContextId context_id, Optional<u64> pa
: m_web_content_client(web_content_client)
, m_context_id(context_id)
, m_page_id(page_id)
- , m_presenter(m_scene, canvas_surfaces, page_id.has_value())
+ , m_presenter(canvas_surfaces, page_id.has_value())
+ , m_presents_to_client(page_id.has_value())
, m_caret_blink_timer([this] { return damage_rect_of_blinking_carets(); }, move(schedule_caret_repaint))
, m_request_animation_frames(move(request_animation_frames))
{
@@ -132,7 +133,7 @@ void ContextState::stop_presenting_to_client()
m_pointer_in_nested_contexts = {};
end_keyboard_scroll_gesture();
m_elastic_overscroll_controller.forget();
- m_presenter.stop_presenting_to_client();
+ m_presents_to_client = false;
}
void ContextState::set_parent_context(Optional<Web::CompositorContextId> parent_context_id)
@@ -140,11 +141,6 @@ void ContextState::set_parent_context(Optional<Web::CompositorContextId> parent_
m_parent_context_id = parent_context_id;
}
-void ContextState::apply_display_list_resource_transaction(Compositing::DisplayListResourceTransaction&& resource_transaction)
-{
- m_scene.apply_resource_transaction(move(resource_transaction));
-}
-
void ContextState::install_display_list_update(
NonnullRefPtr<Compositing::DisplayList> display_list,
Compositing::AccumulatedVisualContextTree visual_context_tree,
@@ -202,27 +198,28 @@ Gfx::IntRect ContextState::damage_rect_of_blinking_carets()
return;
auto rect = visual_context_tree.transform_rect_to_viewport(context.spatial, bounding_rect.template to_type<float>(), presented_scroll_state_snapshot);
if (!isfinite(rect.x()) || !isfinite(rect.y()) || !isfinite(rect.width()) || !isfinite(rect.height())) {
- damage_rect = { {}, m_presenter.viewport_size() };
+ damage_rect = { {}, m_viewport_size };
return;
}
- rect.intersect(Gfx::IntRect { {}, m_presenter.viewport_size() }.to_type<float>());
+ rect.intersect(Gfx::IntRect { {}, m_viewport_size }.to_type<float>());
if (!rect.is_empty())
damage_rect.unite(Gfx::enclosing_int_rect(rect).inflated(1, 1, 1, 1));
});
- damage_rect.intersect({ {}, m_presenter.viewport_size() });
+ damage_rect.intersect({ {}, m_viewport_size });
return damage_rect;
}
-void ContextState::update_visual_context_tree(Compositing::AccumulatedVisualContextTree visual_context_tree, Compositing::DisplayListResourceTransaction&& resource_transaction)
+bool ContextState::update_visual_context_tree(Compositing::AccumulatedVisualContextTree visual_context_tree)
{
- if (!m_scene.replace_visual_context_tree(move(visual_context_tree), move(resource_transaction)))
- return;
+ if (!m_scene.replace_visual_context_tree(move(visual_context_tree)))
+ return false;
// A constraints refresh changes sticky payloads without a new snapshot, and the snapshot that
// pairs with this tree arrives in a separate message.
Compositing::resolve_sticky_offsets(*m_scene.visual_context_tree(), m_scroll_state_snapshot);
if (m_has_async_scrolling_state)
rebuild_wheel_hit_test_targets();
+ return true;
}
void ContextState::update_scroll_state(Compositing::ScrollStateSnapshot&& scroll_state_snapshot, Compositing::KeyboardScrollState keyboard_scroll_state)
@@ -241,11 +238,6 @@ void ContextState::update_scroll_state(Compositing::ScrollStateSnapshot&& scroll
adopt_keyboard_scroll_state(move(keyboard_scroll_state));
}
-void ContextState::set_video_sink(Compositing::VideoSinkResourceId frame_id, RefPtr<Media::DisplayingVideoSink> sink)
-{
- m_scene.set_video_sink(frame_id, move(sink));
-}
-
void ContextState::invalidate_wheel_event_listener_state(u64 generation)
{
m_wheel_gesture_routing.invalidate_wheel_event_listener_state(generation);
@@ -272,7 +264,7 @@ void ContextState::end_keyboard_scroll_gesture()
Optional<ContextState::KeyScroll> ContextState::key_scroll_for(Web::KeyEvent const& event) const
{
- if (!presents_to_client() || m_presenter.ui_overlays().paused_debugger.has_value()
+ if (!presents_to_client() || m_paused_debugger_overlay_is_shown
|| m_visibility != Compositing::ContextVisibility::Visible
|| !Web::is_keyboard_scroll_key(event.key, event.modifiers)
|| !m_keyboard_scroll_controller.has_target()
@@ -2010,31 +2002,25 @@ bool ContextState::has_pending_async_scroll_updates() const
return m_async_scroll_update_outbox.has_updates(user_scroll_gesture_state());
}
-void ContextState::viewport_size_updated(Gfx::IntSize viewport_size, double device_pixel_ratio, Compositing::WindowResizingInProgress window_resize_in_progress)
+void ContextState::viewport_size_updated(Gfx::IntSize viewport_size)
{
m_scene.forget_whether_animated_content_may_affect_viewport();
- if (m_presenter.viewport_size() != viewport_size)
+ if (m_viewport_size != viewport_size)
m_keyboard_scroll_controller.forget_target();
- auto is_page_presentation_context = m_page_id.has_value() && !m_parent_context_id.has_value();
- m_presenter.set_viewport_size(viewport_size, device_pixel_ratio, is_page_presentation_context ? window_resize_in_progress : Compositing::WindowResizingInProgress::No);
+ m_viewport_size = viewport_size;
}
-bool ContextState::set_ui_overlays(Compositing::UIOverlays overlays)
+void ContextState::set_paused_debugger_overlay_is_shown(bool is_shown)
{
- if (m_presenter.ui_overlays() == overlays)
- return false;
-
- if (overlays.paused_debugger.has_value())
+ if (is_shown)
end_keyboard_scroll_gesture();
- m_presenter.set_ui_overlays(move(overlays));
- return true;
+ m_paused_debugger_overlay_is_shown = is_shown;
}
-bool ContextState::set_display_metadata(Optional<u64> display_id, double refresh_rate)
+void ContextState::set_display_metadata(Optional<u64> display_id, double refresh_rate)
{
m_display_id = display_id;
m_display_refresh_rate = refresh_rate;
- return m_presenter.pending_present_frame_scheduled();
}
bool ContextState::set_visibility(Compositing::ContextVisibility visibility)
@@ -2059,18 +2045,16 @@ Vector<Web::CompositorScrollOffset> ContextState::scroll_offsets() const
return scroll_offsets;
}
-bool ContextState::has_pending_present_frame_scheduled_on(Optional<u64> display_id) const
-{
- return m_presenter.pending_present_frame_scheduled() && m_display_id == display_id;
-}
-
-ContextPresenter::FrameContent ContextState::frame_content(Compositing::ScrollStateSnapshot const& presented_scroll_state_snapshot, CompositedContextResolver const* composited_context_resolver) const
+FrameInputs ContextState::frame_inputs_as_presented_now()
{
+ auto stretched_scroll_state_snapshot = scroll_state_snapshot_stretched_by_elastic_overscrolls();
+ auto presented_scroll_state_snapshot = stretched_scroll_state_snapshot.has_value() ? stretched_scroll_state_snapshot.release_value() : m_scroll_state_snapshot;
+ auto scrollbars = m_scrollbar_controller.scrollbars_of_frame(presented_scroll_state_snapshot);
return {
- .presented_scroll_state_snapshot = presented_scroll_state_snapshot,
- .scrollbar_controller = m_scrollbar_controller,
+ .visual_context_tree = m_scene.visual_context_tree_for_compositing(),
+ .presented_scroll_state_snapshot = move(presented_scroll_state_snapshot),
+ .scrollbars = move(scrollbars),
.viewport_scroll_node_index = m_async_scroll_tree.viewport_scroll_node_index(),
- .composited_context_resolver = composited_context_resolver,
};
}
@@ -2114,7 +2098,7 @@ void ContextState::report_scrollbar_visibility_changes()
m_web_content_client.overlay_scrollbar_visibilities_changed(changes);
}
-Optional<PendingFrame> ContextState::advance_scrollbar_fades(MonotonicTime frame_time)
+Gfx::IntRect ContextState::advance_scrollbar_fades_and_return_damage_rect(MonotonicTime frame_time)
{
if (!m_scene.visual_context_tree().has_value())
return {};
@@ -2122,48 +2106,29 @@ Optional<PendingFrame> ContextState::advance_scrollbar_fades(MonotonicTime frame
auto const& presented_scroll_state_snapshot = stretched_scroll_state_snapshot.has_value() ? *stretched_scroll_state_snapshot : m_scroll_state_snapshot;
auto damage_rect = m_scrollbar_controller.advance_fades(m_scene.visual_context_tree_for_compositing(), presented_scroll_state_snapshot, frame_time);
report_scrollbar_visibility_changes();
- auto viewport_rect = m_presenter.viewport_rect_for_ui_overlay();
- if (damage_rect.is_empty() || !viewport_rect.has_value())
- return {};
- return PendingFrame { *viewport_rect, damage_rect };
-}
-
-Optional<PreparedFrame> ContextState::prepare_frame(DisplayListPlayerSkia& display_list_player, PendingFrame pending_frame, CompositedContextResolver const* composited_context_resolver)
-{
- update_scrollbar_visibility();
- auto stretched_scroll_state_snapshot = scroll_state_snapshot_stretched_by_elastic_overscrolls();
- auto const& presented_scroll_state_snapshot = stretched_scroll_state_snapshot.has_value() ? *stretched_scroll_state_snapshot : m_scroll_state_snapshot;
- return m_presenter.prepare_frame(display_list_player, pending_frame, frame_content(presented_scroll_state_snapshot, composited_context_resolver));
+ return damage_rect;
}
-bool ContextState::present_synchronously(DisplayListPlayerSkia& display_list_player, CompositedContextResolver const* composited_context_resolver)
+Optional<FrameInputs> ContextState::frame_inputs()
{
update_scrollbar_visibility();
- auto stretched_scroll_state_snapshot = scroll_state_snapshot_stretched_by_elastic_overscrolls();
- auto const& presented_scroll_state_snapshot = stretched_scroll_state_snapshot.has_value() ? *stretched_scroll_state_snapshot : m_scroll_state_snapshot;
- return m_presenter.present_synchronously(display_list_player, frame_content(presented_scroll_state_snapshot, composited_context_resolver));
+ if (!m_scene.display_list())
+ return {};
+ return frame_inputs_as_presented_now();
}
-Optional<PendingFrame> ContextState::paint_screenshot(DisplayListPlayerSkia& display_list_player, Gfx::ShareableBitmap& target_bitmap, CompositedContextResolver const* composited_context_resolver)
+ContextState::ScreenshotInputs ContextState::frame_inputs_for_screenshot()
{
- VERIFY(can_paint_screenshot(target_bitmap));
+ VERIFY(m_scene.display_list());
// Screenshot requests can arrive between display ticks, so sample animations and scrollbar visibility at capture
// time.
auto capture_time = MonotonicTime::now();
advance_visual_animations(capture_time);
update_scrollbar_visibility();
- auto scrollbar_fade_frame = advance_scrollbar_fades(capture_time);
-
- auto stretched_scroll_state_snapshot = scroll_state_snapshot_stretched_by_elastic_overscrolls();
- auto const& presented_scroll_state_snapshot = stretched_scroll_state_snapshot.has_value() ? *stretched_scroll_state_snapshot : m_scroll_state_snapshot;
- m_presenter.paint_screenshot(display_list_player, target_bitmap, frame_content(presented_scroll_state_snapshot, composited_context_resolver));
- return scrollbar_fade_frame;
-}
+ auto scrollbar_fade_damage_rect = advance_scrollbar_fades_and_return_damage_rect(capture_time);
-bool ContextState::can_paint_screenshot(Gfx::ShareableBitmap& target_bitmap) const
-{
- return m_scene.display_list() && target_bitmap.is_valid() && target_bitmap.bitmap();
+ return { .frame_inputs = frame_inputs_as_presented_now(), .scrollbar_fade_damage_rect = scrollbar_fade_damage_rect };
}
Optional<ContextState::VisualViewportScrollDelta> ContextState::apply_visual_viewport_scroll_delta(Gfx::FloatPoint delta)
@@ -2585,7 +2550,7 @@ void ContextState::rebuild_wheel_hit_test_targets()
bool ContextState::visual_animations_need_frame()
{
- return m_scene.visual_animations_need_frame(m_scroll_state_snapshot, m_presenter.viewport_size());
+ return m_scene.visual_animations_need_frame(m_scroll_state_snapshot, m_viewport_size);
}
bool ContextState::advance_visual_animations(MonotonicTime now)
diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.h
index a196ea6f454..0b475059ab6 100644
--- a/Services/Compositor/ContextState.h
+++ b/Services/Compositor/ContextState.h
@@ -172,7 +172,7 @@ public:
bool can_dispatch_input_to_web_content() const { return m_page_id.has_value(); }
Optional<u64> page_id() const { return m_page_id; }
- bool presents_to_client() const { return m_presenter.presents_to_client(); }
+ bool presents_to_client() const { return m_presents_to_client; }
void stop_presenting_to_client();
void set_parent_context(Optional<Web::CompositorContextId>);
@@ -181,18 +181,13 @@ public:
ContextPresenter& presenter() { return m_presenter; }
ContextPresenter const& presenter() const { return m_presenter; }
- void apply_display_list_resource_transaction(Compositing::DisplayListResourceTransaction&&);
void install_display_list_update(
NonnullRefPtr<Compositing::DisplayList>,
Compositing::AccumulatedVisualContextTree,
Compositing::ScrollStateSnapshot&&);
- void update_visual_context_tree(Compositing::AccumulatedVisualContextTree, Compositing::DisplayListResourceTransaction&&);
+ // Returns false, leaving everything as it was, for a tree that does not fit the installed display list.
+ bool update_visual_context_tree(Compositing::AccumulatedVisualContextTree);
void update_scroll_state(Compositing::ScrollStateSnapshot&&, Compositing::KeyboardScrollState);
- void set_video_sink(Compositing::VideoSinkResourceId, RefPtr<Media::DisplayingVideoSink>);
- HashMap<u64, Media::VideoSinkHandle> const& video_sink_handles() const { return m_scene.video_sink_handles(); }
- bool has_image_frame(Compositing::ImageFrameResourceId id) { return m_scene.resource_storage().has_image_frame(id); }
- Gfx::DecodedImageFrame const& image_frame(Compositing::ImageFrameResourceId id) { return m_scene.resource_storage().image_frame(id); }
- void replace_image_frame_pixels(Compositing::ImageFrameResourceId id, Gfx::DecodedImageFrame frame) { m_scene.resource_storage().replace_image_frame_pixels(id, move(frame)); }
void invalidate_wheel_event_listener_state(u64 generation);
void invalidate_keyboard_scroll_state(u64 generation);
@@ -283,7 +278,7 @@ public:
Optional<PendingFrame> apply_scroll_requests(ReadonlySpan<Compositing::ScrollRequest>);
void cancel_smooth_scroll(Web::AsyncScrollNodeStableID);
Optional<Gfx::IntRect> advance_smooth_scroll_animations(MonotonicTime now);
- bool needs_animation_frames() { return has_active_smooth_scroll_animations() || has_active_scroll_fling() || m_elastic_overscroll_controller.has_rebound() || visual_animations_need_frame() || m_presenter.ui_overlay_fades_need_frame() || m_scrollbar_controller.fades_need_frame(MonotonicTime::now()); }
+ bool needs_animation_frames() { return has_active_smooth_scroll_animations() || has_active_scroll_fling() || m_elastic_overscroll_controller.has_rebound() || visual_animations_need_frame() || m_scrollbar_controller.fades_need_frame(MonotonicTime::now()); }
bool has_active_scroll_fling() const { return m_scroll_fling_controller.is_active(); }
// The wheel event of the next step of the fling, which is scrolled by like a wheel event from the UI.
@@ -309,7 +304,7 @@ public:
};
void set_scroll_capabilities(ScrollCapabilities const&);
Optional<Gfx::IntRect> advance_elastic_overscroll_rebounds(MonotonicTime frame_time);
- Optional<PendingFrame> advance_scrollbar_fades(MonotonicTime frame_time);
+ Gfx::IntRect advance_scrollbar_fades_and_return_damage_rect(MonotonicTime frame_time);
// The installed scrolling state, its routing admission, and how far the given scroller is stretched, as JSON.
String scroll_state_for_testing(Web::AsyncScrollNodeStableID scroller) const;
Web::InputTraceRecorder& input_trace() { return m_input_trace; }
@@ -323,10 +318,11 @@ public:
Compositing::PendingAsyncScrollUpdates take_pending_async_scroll_updates();
bool has_pending_async_scroll_updates() const;
- void viewport_size_updated(Gfx::IntSize, double device_pixel_ratio, Compositing::WindowResizingInProgress);
- bool set_ui_overlays(Compositing::UIOverlays);
+ Gfx::IntSize viewport_size() const { return m_viewport_size; }
+ void viewport_size_updated(Gfx::IntSize);
+ void set_paused_debugger_overlay_is_shown(bool);
- bool set_display_metadata(Optional<u64> display_id, double refresh_rate);
+ void set_display_metadata(Optional<u64> display_id, double refresh_rate);
Optional<u64> display_id() const { return m_display_id; }
double display_refresh_rate() const { return m_display_refresh_rate; }
bool set_visibility(Compositing::ContextVisibility);
@@ -350,12 +346,15 @@ public:
Vector<Web::CompositorScrollOffset> scroll_offsets() const;
bool display_tick_requested() const { return rendering_opportunity_requested() || clock_tick_requested(); }
- bool has_pending_present_frame_scheduled_on(Optional<u64> display_id) const;
- Optional<PreparedFrame> prepare_frame(DisplayListPlayerSkia&, PendingFrame, CompositedContextResolver const*);
- bool present_synchronously(DisplayListPlayerSkia&, CompositedContextResolver const*);
- bool can_paint_screenshot(Gfx::ShareableBitmap&) const;
- // Returns the scrollbar fade damage that the screenshot did not present on screen.
- Optional<PendingFrame> paint_screenshot(DisplayListPlayerSkia&, Gfx::ShareableBitmap&, CompositedContextResolver const*);
+ // Each frame shows the scrollbars as of when it is painted, so this updates which of them are shown. Empty until a
+ // display list is installed.
+ Optional<FrameInputs> frame_inputs();
+ struct ScreenshotInputs {
+ FrameInputs frame_inputs;
+ // The scrollbar fade damage that the screenshot does not present on screen.
+ Gfx::IntRect scrollbar_fade_damage_rect;
+ };
+ ScreenshotInputs frame_inputs_for_screenshot();
private:
struct ActiveSmoothScrollAnimation {
@@ -469,7 +468,7 @@ private:
// The smooth scroll that a press beside the thumb started, while it lasts.
ActiveSmoothScrollAnimation* running_scrollbar_press_scroll();
void rebuild_wheel_hit_test_targets();
- ContextPresenter::FrameContent frame_content(Compositing::ScrollStateSnapshot const& presented_scroll_state_snapshot, CompositedContextResolver const*) const;
+ FrameInputs frame_inputs_as_presented_now();
Gfx::IntRect damage_rect_of_blinking_carets();
void update_scrollbar_visibility();
void report_scrollbar_visibility_changes();
@@ -482,6 +481,9 @@ private:
ContextScene m_scene;
ContextPresenter m_presenter;
+ bool m_presents_to_client { false };
+ Gfx::IntSize m_viewport_size;
+ bool m_paused_debugger_overlay_is_shown { false };
Compositing::ScrollStateSnapshot m_scroll_state_snapshot;
Compositing::AsyncScrollTree m_async_scroll_tree;
diff --git a/Services/Compositor/DisplayListPlayerSkia.cpp b/Services/Compositor/DisplayListPlayerSkia.cpp
index 557ed5f8e75..05b19e5463a 100644
--- a/Services/Compositor/DisplayListPlayerSkia.cpp
+++ b/Services/Compositor/DisplayListPlayerSkia.cpp
@@ -72,10 +72,10 @@ void DisplayListPlayerSkia::execute(
RefPtr<Gfx::PaintingSurface> surface,
OwnedCanvasSurfaces const* canvas_surfaces,
CompositedContextResolver const* composited_context_resolver,
- ScrollbarController const* scrollbar_controller)
+ ReadonlySpan<ScrollbarController::ScrollbarOfFrame> scrollbars_of_frame)
{
TemporaryChange composited_context_resolver_change { m_composited_context_resolver, composited_context_resolver };
- TemporaryChange scrollbar_controller_change { m_scrollbar_controller, scrollbar_controller };
+ TemporaryChange scrollbars_of_frame_change { m_scrollbars_of_frame, scrollbars_of_frame };
raster_cache.drop_clip_paths_not_used_since_last_frame();
TemporaryChange raster_cache_change { m_raster_cache, &raster_cache };
DisplayListPlayer::execute(
@@ -199,9 +199,13 @@ static void paint_scrollbar_into_surface(Gfx::PaintingSurface& surface, Scrollba
canvas.drawRRect(thumb_rrect, stroke_paint);
}
-void DisplayListPlayerSkia::paint_scrollbar(Gfx::PaintingSurface& surface, ScrollbarController::PresentedScrollbar const& scrollbar)
+void DisplayListPlayerSkia::paint_scrollbars_painted_by_compositor(Gfx::PaintingSurface& surface, ReadonlySpan<ScrollbarController::ScrollbarOfFrame> scrollbars_of_frame)
{
- paint_scrollbar_into_surface(surface, scrollbar);
+ for (auto const& scrollbar : scrollbars_of_frame) {
+ if (!scrollbar.is_painted_by_compositor)
+ continue;
+ paint_scrollbar_into_surface(surface, scrollbar.presented_with_colors(scrollbar.thumb_color, scrollbar.thumb_outline_color, scrollbar.track_color));
+ }
}
static SkMatrix vertical_glyph_run_rotation(Gfx::IntRect const& rect)
@@ -1328,6 +1332,8 @@ void DisplayListPlayerSkia::play_command(PaintNestedDisplayList const& command)
{
auto& canvas = surface().canvas();
auto const& nested_display_list = resource_storage().display_list_resource(command.display_list_id);
+ // The scrollbars of this context do not belong to the scroll nodes of a nested display list.
+ TemporaryChange<ReadonlySpan<ScrollbarController::ScrollbarOfFrame>> scrollbars_of_frame_change { m_scrollbars_of_frame, {} };
// Rasterize immutable nested lists (SVG images and masks) at list resolution and reuse their snapshots.
// The first paint of a list rasterizes only the visible portion, so lists replaced every frame do not paint
@@ -1427,8 +1433,6 @@ void DisplayListPlayerSkia::play_command(PaintNestedDisplayList const& command)
canvas.scale(command.rect.width() / command.list_size.width(), command.rect.height() / command.list_size.height());
}
ScrollStateSnapshot scroll_state_snapshot;
- // The scrollbars of this context do not belong to the scroll nodes of a nested display list.
- TemporaryChange<ScrollbarController const*> scrollbar_controller_change { m_scrollbar_controller, nullptr };
execute_nested_display_list(*nested_display_list.display_list, nested_display_list.visual_context_tree, scroll_state_snapshot);
canvas.restore();
}
@@ -1471,9 +1475,11 @@ void DisplayListPlayerSkia::play_command(CompositorNestedContextWheelRegion cons
void DisplayListPlayerSkia::play_command(PaintScrollBar const& command)
{
- if (m_scrollbar_controller) {
- if (auto scrollbar = m_scrollbar_controller->presented_scrollbar_painted_by_display_list(command.scroll_node_index, command.vertical, command.thumb_color, command.thumb_outline_color, command.track_color, active_scroll_state()); scrollbar.has_value()) {
- paint_scrollbar_into_surface(surface(), *scrollbar);
+ // A scrollbar command of the display list with no scrollbar of the frame is painted as the command gives it. The
+ // colors are the ones the display list resolved for the page, which it may have darkened.
+ for (auto const& scrollbar_of_frame : m_scrollbars_of_frame) {
+ if (!scrollbar_of_frame.is_painted_by_compositor && scrollbar_of_frame.scroll_node_index == command.scroll_node_index && scrollbar_of_frame.vertical == command.vertical) {
+ paint_scrollbar_into_surface(surface(), scrollbar_of_frame.presented_with_colors(command.thumb_color, command.thumb_outline_color, command.track_color));
return;
}
}
diff --git a/Services/Compositor/DisplayListPlayerSkia.h b/Services/Compositor/DisplayListPlayerSkia.h
index 4c957a966c0..34dae681e51 100644
--- a/Services/Compositor/DisplayListPlayerSkia.h
+++ b/Services/Compositor/DisplayListPlayerSkia.h
@@ -52,11 +52,11 @@ public:
RefPtr<Gfx::PaintingSurface>,
OwnedCanvasSurfaces const*,
CompositedContextResolver const*,
- ScrollbarController const* = nullptr);
+ ReadonlySpan<ScrollbarController::ScrollbarOfFrame> = {});
void flush(Gfx::PaintingSurface&) override;
void flush_async(Gfx::PaintingSurface&, Function<void()>&&);
- void paint_scrollbar(Gfx::PaintingSurface&, ScrollbarController::PresentedScrollbar const&);
+ void paint_scrollbars_painted_by_compositor(Gfx::PaintingSurface&, ReadonlySpan<ScrollbarController::ScrollbarOfFrame>);
private:
#define DECLARE_PLAY_COMMAND(command_type) \
@@ -91,7 +91,7 @@ private:
RefPtr<Gfx::SkiaBackendContext> m_skia_backend_context;
CompositedContextResolver const* m_composited_context_resolver { nullptr };
// Says how opaque the scrollbars that the display list paints are.
- ScrollbarController const* m_scrollbar_controller { nullptr };
+ ReadonlySpan<ScrollbarController::ScrollbarOfFrame> m_scrollbars_of_frame;
DisplayListRasterCache* m_raster_cache { nullptr };
DisplayListRasterCache& raster_cache() const { return *m_raster_cache; }
};
diff --git a/Services/Compositor/ScrollbarController.cpp b/Services/Compositor/ScrollbarController.cpp
index 8b696cb67b7..ebfb1acb242 100644
--- a/Services/Compositor/ScrollbarController.cpp
+++ b/Services/Compositor/ScrollbarController.cpp
@@ -5,7 +5,6 @@
*/
#include <AK/Math.h>
-#include <Compositor/DisplayListPlayerSkia.h>
#include <Compositor/ScrollbarController.h>
#include <LibCompositing/DisplayList/AccumulatedVisualContext.h>
#include <LibCompositing/Scrolling/AsyncScrollTree.h>
@@ -446,56 +445,53 @@ static Gfx::FloatRect interpolated_rect(Gfx::IntRect const& from, Gfx::IntRect c
};
}
-ScrollbarController::PresentedScrollbar ScrollbarController::presented_scrollbar(size_t scrollbar_index, Compositing::ScrollStateSnapshot const& scroll_state_snapshot, Color thumb_color, Color thumb_outline_color, Color track_color) const
+Vector<ScrollbarController::ScrollbarOfFrame> ScrollbarController::scrollbars_of_frame(Compositing::ScrollStateSnapshot const& scroll_state_snapshot) const
{
- auto const& scrollbar = m_scrollbars[scrollbar_index];
- auto progress = expansion(scrollbar_index);
-
- auto thin_thumb_rect = thumb_rect_kept_inside_track(translated_thumb_rect(scrollbar, scroll_state_snapshot, false), scrollbar.track_rect, scrollbar.vertical);
- auto expanded_thumb_rect = thumb_rect_kept_inside_track(translated_thumb_rect(scrollbar, scroll_state_snapshot, true), scrollbar.expanded_gutter_rect, scrollbar.vertical);
- // An empty thumb has nothing to grow from or to.
- if (thin_thumb_rect.is_empty())
- thin_thumb_rect = expanded_thumb_rect;
- if (expanded_thumb_rect.is_empty())
- expanded_thumb_rect = thin_thumb_rect;
+ Vector<ScrollbarOfFrame> scrollbars_of_frame;
+ scrollbars_of_frame.ensure_capacity(m_scrollbars.size());
+ for (size_t i = 0; i < m_scrollbars.size(); ++i) {
+ auto const& scrollbar = m_scrollbars[i];
+ auto progress = expansion(i);
+
+ auto thin_thumb_rect = thumb_rect_kept_inside_track(translated_thumb_rect(scrollbar, scroll_state_snapshot, false), scrollbar.track_rect, scrollbar.vertical);
+ auto expanded_thumb_rect = thumb_rect_kept_inside_track(translated_thumb_rect(scrollbar, scroll_state_snapshot, true), scrollbar.expanded_gutter_rect, scrollbar.vertical);
+ // An empty thumb has nothing to grow from or to.
+ if (thin_thumb_rect.is_empty())
+ thin_thumb_rect = expanded_thumb_rect;
+ if (expanded_thumb_rect.is_empty())
+ expanded_thumb_rect = thin_thumb_rect;
+
+ scrollbars_of_frame.unchecked_append({
+ .scroll_node_index = scrollbar.scroll_node_index,
+ .vertical = scrollbar.vertical,
+ .is_painted_by_compositor = scrollbar.is_painted_by_compositor,
+ .gutter_rect = interpolated_rect(scrollbar.track_rect, scrollbar.expanded_gutter_rect, progress),
+ .thumb_rect = interpolated_rect(thin_thumb_rect, expanded_thumb_rect, progress),
+ .expansion = progress,
+ .opacity = opacity(i),
+ .thumb_color = scrollbar.thumb_color,
+ .thumb_outline_color = scrollbar.thumb_outline_color,
+ .track_color = scrollbar.track_color,
+ .thin_and_expanded_gutter_rect = scrollbar.gutter_rect.united(scrollbar.expanded_gutter_rect),
+ });
+ }
+ return scrollbars_of_frame;
+}
+ScrollbarController::PresentedScrollbar ScrollbarController::ScrollbarOfFrame::presented_with_colors(Color thumb_color, Color thumb_outline_color, Color track_color) const
+{
// The gutter of a thin scrollbar is not painted, so the gutter grows out of the thin track as it fades in.
- auto track_alpha = roundf(static_cast<float>(track_color.alpha()) * progress);
+ auto track_alpha = roundf(static_cast<float>(track_color.alpha()) * expansion);
return PresentedScrollbar {
- .gutter_rect = interpolated_rect(scrollbar.track_rect, scrollbar.expanded_gutter_rect, progress),
- .thumb_rect = interpolated_rect(thin_thumb_rect, expanded_thumb_rect, progress),
+ .gutter_rect = gutter_rect,
+ .thumb_rect = thumb_rect,
.thumb_color = thumb_color,
.thumb_outline_color = thumb_outline_color,
.track_color = track_color.with_alpha(static_cast<u8>(track_alpha)),
- .opacity = opacity(scrollbar_index),
+ .opacity = opacity,
};
}
-Optional<ScrollbarController::PresentedScrollbar> ScrollbarController::presented_scrollbar_painted_by_display_list(Compositing::SpatialNodeIndex scroll_node_index, bool vertical, Color thumb_color, Color thumb_outline_color, Color track_color, Compositing::ScrollStateSnapshot const& scroll_state_snapshot) const
-{
- for (size_t i = 0; i < m_scrollbars.size(); ++i) {
- auto const& scrollbar = m_scrollbars[i];
- if (!scrollbar.is_painted_by_compositor && scrollbar.scroll_node_index == scroll_node_index && scrollbar.vertical == vertical)
- return presented_scrollbar(i, scroll_state_snapshot, thumb_color, thumb_outline_color, track_color);
- }
- return {};
-}
-
-bool ScrollbarController::paint(Gfx::PaintingSurface& surface, DisplayListPlayerSkia& display_list_player, Compositing::ScrollStateSnapshot const& scroll_state_snapshot) const
-{
- bool painted_a_scrollbar = false;
- for (size_t i = 0; i < m_scrollbars.size(); ++i) {
- auto const& scrollbar = m_scrollbars[i];
- if (!scrollbar.is_painted_by_compositor)
- continue;
- if (opacity(i) <= 0)
- continue;
- display_list_player.paint_scrollbar(surface, presented_scrollbar(i, scroll_state_snapshot, scrollbar.thumb_color, scrollbar.thumb_outline_color, scrollbar.track_color));
- painted_a_scrollbar = true;
- }
- return painted_a_scrollbar;
-}
-
bool ScrollbarController::is_expanded(size_t scrollbar_index) const
{
return m_hovered_scrollbar_index == scrollbar_index || m_captured_scrollbar_index == scrollbar_index;
diff --git a/Services/Compositor/ScrollbarController.h b/Services/Compositor/ScrollbarController.h
index e0e07dd073d..bb62d15b380 100644
--- a/Services/Compositor/ScrollbarController.h
+++ b/Services/Compositor/ScrollbarController.h
@@ -57,6 +57,22 @@ public:
float opacity { 1 };
};
+ struct ScrollbarOfFrame {
+ Compositing::SpatialNodeIndex scroll_node_index;
+ bool vertical { false };
+ bool is_painted_by_compositor { false };
+ Gfx::FloatRect gutter_rect;
+ Gfx::FloatRect thumb_rect;
+ float expansion { 0 };
+ float opacity { 1 };
+ Color thumb_color;
+ Color thumb_outline_color;
+ Color track_color;
+ Gfx::IntRect thin_and_expanded_gutter_rect;
+
+ PresentedScrollbar presented_with_colors(Color thumb_color, Color thumb_outline_color, Color track_color) const;
+ };
+
// A scroll offset outside the scroll range moves the thumb past an end of its track, where it is cut short instead.
static Gfx::IntRect thumb_rect_kept_inside_track(Gfx::IntRect thumb_rect, Gfx::IntRect const& track_rect, bool vertical);
@@ -82,9 +98,7 @@ public:
bool fades_need_frame(MonotonicTime now) const;
// Returns the rect in the viewport of the scrollbars whose opacity or geometry changed.
Gfx::IntRect advance_fades(Compositing::AccumulatedVisualContextTree const&, Compositing::ScrollStateSnapshot const&, MonotonicTime frame_time);
- // A scrollbar command of the display list with no scrollbar here is painted as the command gives it. The colors are
- // the ones the display list resolved for the page, which it may have darkened.
- Optional<PresentedScrollbar> presented_scrollbar_painted_by_display_list(Compositing::SpatialNodeIndex scroll_node_index, bool vertical, Color thumb_color, Color thumb_outline_color, Color track_color, Compositing::ScrollStateSnapshot const&) const;
+ Vector<ScrollbarOfFrame> scrollbars_of_frame(Compositing::ScrollStateSnapshot const&) const;
bool is_empty() const { return m_scrollbars.is_empty(); }
Vector<Compositing::AsyncScrollbar> const& scrollbars() const { return m_scrollbars; }
@@ -109,7 +123,6 @@ public:
bool set_hovered_scrollbar(Optional<size_t>);
Optional<ScrollOffset> scroll_offset_for_drag(Compositing::AsyncScrollTree const&, Compositing::ScrollStateSnapshot const&, Drag const&) const;
- bool paint(Gfx::PaintingSurface&, DisplayListPlayerSkia&, Compositing::ScrollStateSnapshot const&) const;
private:
struct Visibility {
@@ -127,7 +140,6 @@ private:
bool is_expanded(size_t scrollbar_index) const;
float opacity(size_t scrollbar_index) const;
float expansion(size_t scrollbar_index) const;
- PresentedScrollbar presented_scrollbar(size_t scrollbar_index, Compositing::ScrollStateSnapshot const&, Color thumb_color, Color thumb_outline_color, Color track_color) const;
Optional<Gfx::IntRect> rect_in_viewport(size_t scrollbar_index, Compositing::AccumulatedVisualContextTree const&, Compositing::ScrollStateSnapshot const&) const;
float primary_position_of_captured_drag(Compositing::AccumulatedVisualContextTree const&, Compositing::ScrollStateSnapshot const&, Gfx::FloatPoint position);
diff --git a/Tests/Compositor/TestScrollbarController.cpp b/Tests/Compositor/TestScrollbarController.cpp
index c0439d06a5f..139e37013f8 100644
--- a/Tests/Compositor/TestScrollbarController.cpp
+++ b/Tests/Compositor/TestScrollbarController.cpp
@@ -143,9 +143,11 @@ static Compositing::AsyncScrollbar scrollbar_painted_by_display_list()
static Compositor::ScrollbarController::PresentedScrollbar presented_scrollbar(Compositor::ScrollbarController const& controller, Compositing::ScrollStateSnapshot const& scroll_state_snapshot = {})
{
- auto scrollbar = controller.presented_scrollbar_painted_by_display_list(Compositing::SpatialNodeIndex { 1 }, true, Gfx::Color(0, 0, 0, 100), Gfx::Color(255, 255, 255, 64), Gfx::Color(0, 0, 0, 20), scroll_state_snapshot);
- VERIFY(scrollbar.has_value());
- return *scrollbar;
+ for (auto const& scrollbar : controller.scrollbars_of_frame(scroll_state_snapshot)) {
+ if (!scrollbar.is_painted_by_compositor && scrollbar.scroll_node_index == Compositing::SpatialNodeIndex { 1 } && scrollbar.vertical)
+ return scrollbar.presented_with_colors(Gfx::Color(0, 0, 0, 100), Gfx::Color(255, 255, 255, 64), Gfx::Color(0, 0, 0, 20));
+ }
+ VERIFY_NOT_REACHED();
}
static float opacity_of_scrollbar(Compositor::ScrollbarController const& controller)