Skip to content

Truly independent web browser

LibWebView+Compositor: Add an advanced setting to disable HDR layers

Zaggy10247824369eab68
diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp
index c98486815ba..5f8ffc690d7 100644
--- a/Libraries/LibWebView/Application.cpp
+++ b/Libraries/LibWebView/Application.cpp
@@ -163,6 +163,8 @@ struct ApplicationSettingsObserver final : public SettingsObserver {
{
if (id == ConfigVariableID::MaximumDiskCacheSize)
Application::request_server_manager().disk_cache_settings_changed();
+ else if (id == ConfigVariableID::DisableHighDynamicRangeSurfaces)
+ Application::the().update_compositor_high_dynamic_range_surfaces();
}
};
@@ -1445,6 +1447,14 @@ void Application::update_compositor_ui_overlays(Web::CompositorContextId context
m_compositor_client->async_set_ui_overlays(context_id, overlays);
}
+void Application::update_compositor_high_dynamic_range_surfaces()
+{
+ if (!can_send_compositor_process_ipc(m_compositor_client))
+ return;
+ auto disabled = settings().config_variable_as_bool(ConfigVariableID::DisableHighDynamicRangeSurfaces);
+ m_compositor_client->async_set_window_server_may_show_high_dynamic_range(!disabled);
+}
+
void Application::update_compositor_display_metadata(Web::CompositorContextId context_id, Optional<u64> display_id, double refresh_rate)
{
if (!can_send_compositor_process_ipc(m_compositor_client))
@@ -1888,6 +1898,8 @@ ErrorOr<void> Application::launch_compositor_process()
compositor_reported_gpu_device_identity(move(identity));
};
+ update_compositor_high_dynamic_range_surfaces();
+
m_reported_compositor_gpu_presentation_unavailable = false;
Optional<u64> gpu_presentation_adapter_luid;
#ifdef USE_DIRECTX
diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.h
index 1eef1f396a8..7d6047dc57f 100644
--- a/Libraries/LibWebView/Application.h
+++ b/Libraries/LibWebView/Application.h
@@ -263,6 +263,7 @@ public:
ErrorOr<void> try_register_compositor_context(WebContentClient&, Web::CompositorContextId, Optional<Web::PageId> page_id);
void update_compositor_viewport(Web::CompositorContextId, Gfx::IntSize viewport_size, double device_pixel_ratio, Compositing::WindowResizingInProgress = Compositing::WindowResizingInProgress::No);
void update_compositor_ui_overlays(Web::CompositorContextId, Compositing::UIOverlays const&);
+ void update_compositor_high_dynamic_range_surfaces();
void update_compositor_display_metadata(Web::CompositorContextId, Optional<u64> display_id, double refresh_rate);
void update_compositor_context_visibility(Web::CompositorContextId, Web::HTML::VisibilityState);
void update_compositor_context_presents_from_cpu_memory(Web::CompositorContextId, bool);
diff --git a/Libraries/LibWebView/Settings.cpp b/Libraries/LibWebView/Settings.cpp
index 99c15165d3b..384a406a8c5 100644
--- a/Libraries/LibWebView/Settings.cpp
+++ b/Libraries/LibWebView/Settings.cpp
@@ -199,6 +199,14 @@ static auto const& CONFIG_VARIABLE_DEFINITIONS = *new Array<ConfigVariableDefini
.default_value = true,
.array_element_type = {},
},
+ {
+ .id = ConfigVariableID::DisableHighDynamicRangeSurfaces,
+ .name = "debug.compositor.disable_high_dynamic_range_surfaces"sv,
+ .title = "Disable HDR surfaces"sv,
+ .description = "Draw HDR content into the page tone-mapped to SDR, instead of letting the window server show it in high dynamic range."sv,
+ .default_value = false,
+ .array_element_type = {},
+ },
} };
ReadonlySpan<ConfigVariableDefinition> config_variable_definitions()
diff --git a/Libraries/LibWebView/Settings.h b/Libraries/LibWebView/Settings.h
index 91b24bdb2f8..4710a3f93f2 100644
--- a/Libraries/LibWebView/Settings.h
+++ b/Libraries/LibWebView/Settings.h
@@ -154,6 +154,7 @@ enum class ConfigVariableID : u8 {
MaximumConnectionsPerDownload,
SplitDownloadsWithoutValidators,
RestartStalledConnections,
+ DisableHighDynamicRangeSurfaces,
Count,
};
diff --git a/Services/Compositor/CompositorControlServer.ipc b/Services/Compositor/CompositorControlServer.ipc
index 9b968d4f249..4ea75f987b7 100644
--- a/Services/Compositor/CompositorControlServer.ipc
+++ b/Services/Compositor/CompositorControlServer.ipc
@@ -10,6 +10,8 @@ endpoint CompositorControlServer
{
set_font_service(IPC::TransportHandle handle, IPC::File catalog, u64 catalog_size, u64 generation) =|
+ set_window_server_may_show_high_dynamic_range(bool may_show) =|
+
connect_web_content() => (IPC::TransportHandle handle, i32 web_content_connection_id)
connect_render_clock(i32 web_content_connection_id, IPC::TransportHandle handle) =|
connect_video_presentation(i32 web_content_connection_id, IPC::TransportHandle handle) =|
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index d608942a64e..7c747c5f853 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -455,6 +455,7 @@ void CompositorState::create_context(Web::CompositorContextId context_id, Option
auto& context = *m_presented_contexts.ensure(context_id, [&] {
return make<PresentedContext>(page_id, web_content_client, OwnedCanvasSurfaces { m_canvas_surface_registry, web_content_client.canvas_surface_owner_id() });
});
+ context.presenter.set_window_server_may_show_high_dynamic_range(m_window_server_may_show_high_dynamic_range);
resize_backing_stores_if_needed(context_id, context);
}
@@ -1112,6 +1113,17 @@ void CompositorState::set_context_visibility(Web::CompositorContextId context_id
resume_presentation_after_becoming_visible(context_id, *context);
}
+void CompositorState::set_window_server_may_show_high_dynamic_range(bool may_show)
+{
+ if (m_window_server_may_show_high_dynamic_range == may_show)
+ return;
+ m_window_server_may_show_high_dynamic_range = may_show;
+ for (auto& context_entry : m_presented_contexts) {
+ context_entry.value->presenter.set_window_server_may_show_high_dynamic_range(may_show);
+ present_current_frame(context_entry.key, *context_entry.value);
+ }
+}
+
void CompositorState::set_context_presents_from_cpu_memory(Web::CompositorContextId context_id, bool presents_from_cpu_memory)
{
auto* context = presented_context_if_present(context_id);
diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.h
index 68e961f7492..e72c0bf5afb 100644
--- a/Services/Compositor/CompositorState.h
+++ b/Services/Compositor/CompositorState.h
@@ -147,6 +147,7 @@ public:
void set_display_metadata(Web::CompositorContextId, Optional<u64> display_id, double refresh_rate);
void set_context_visibility(Web::CompositorContextId, Compositing::ContextVisibility);
void set_context_presents_from_cpu_memory(Web::CompositorContextId, bool);
+ void set_window_server_may_show_high_dynamic_range(bool);
void present_frame(Web::CompositorContextId, Gfx::IntRect viewport_rect);
// Delivers the rendering opportunity a context requested now rather than at the next display tick: a
// viewport change that arrived while an animation's opportunity was outstanding starts its update at once.
@@ -349,6 +350,7 @@ private:
void release_synchronized_resize_hold();
Vector<SynchronizedResize> m_synchronized_resizes;
bool m_remote_layer_changes_are_held { false };
+ bool m_window_server_may_show_high_dynamic_range { true };
RefPtr<Core::Timer> m_synchronized_resize_hold_timeout;
HashMap<u64, RemoteLayerState> m_remote_layers;
diff --git a/Services/Compositor/ConnectionFromClient.h b/Services/Compositor/ConnectionFromClient.h
index 6e89cb2e1e6..4cde5c97571 100644
--- a/Services/Compositor/ConnectionFromClient.h
+++ b/Services/Compositor/ConnectionFromClient.h
@@ -30,6 +30,7 @@ private:
virtual void die() override;
virtual void set_font_service(IPC::TransportHandle, IPC::File catalog, u64 catalog_size, u64 generation) override;
+ virtual void set_window_server_may_show_high_dynamic_range(bool may_show) override { m_compositor_state->set_window_server_may_show_high_dynamic_range(may_show); }
virtual Messages::CompositorControlServer::ConnectWebContentResponse connect_web_content() override;
virtual void connect_render_clock(i32 web_content_connection_id, IPC::TransportHandle) override;
virtual void connect_video_presentation(i32 web_content_connection_id, IPC::TransportHandle) override;
diff --git a/Services/Compositor/ContextPresenter.cpp b/Services/Compositor/ContextPresenter.cpp
index bef5b582086..e30debfcb9b 100644
--- a/Services/Compositor/ContextPresenter.cpp
+++ b/Services/Compositor/ContextPresenter.cpp
@@ -660,7 +660,7 @@ ContextPresenter::LayerUpdate ContextPresenter::layer_update_for(FrameInputs con
layers.active_media = m_media_activity.active_media(now);
// An HDR video is a layer from its first frame for as long as it is drawn, even while paused, so that the window
// server keeps showing it brighter than SDR white instead of it going back into the frame, which holds SDR.
- if (m_window_server_may_show_media) {
+ if (m_window_server_may_show_media && m_window_server_may_show_high_dynamic_range) {
for (auto id : m_display_list->referenced_resource_ids().video_sinks) {
LiveMedia media { RustFFI::FfiLiveMediaKind::Video, id };
auto is_active = any_of(layers.active_media, [&](auto const& active) { return active.kind == media.kind && active.id == media.id; });
@@ -899,6 +899,8 @@ bool ContextPresenter::window_server_can_show_media_layers_of(LayerPlan const& p
auto frame = current_video_frame(Compositing::VideoSinkResourceId { layer.media.id });
if (!frame || !frame->surface())
return false;
+ if (!m_window_server_may_show_high_dynamic_range && video_frame_holds_high_dynamic_range(*frame))
+ return false;
}
}
return true;
diff --git a/Services/Compositor/ContextPresenter.h b/Services/Compositor/ContextPresenter.h
index 8eb66a48bd5..6abe4411230 100644
--- a/Services/Compositor/ContextPresenter.h
+++ b/Services/Compositor/ContextPresenter.h
@@ -76,6 +76,8 @@ public:
// Whether the window server may show the canvases and videos of the frames above them, instead of the frames
// holding them.
void set_window_server_may_show_media(bool may_show_media) { m_window_server_may_show_media = may_show_media; }
+ // Otherwise, the frame draws HDR content tone-mapped to SDR.
+ void set_window_server_may_show_high_dynamic_range(bool may_show) { m_window_server_may_show_high_dynamic_range = may_show; }
void did_deliver_frame_without_store() { m_frame_without_store_in_flight = false; }
Gfx::IntSize viewport_size() const { return m_viewport_size; }
@@ -246,6 +248,7 @@ private:
bool m_repaint_everything_after_dropping_layers { false };
bool m_window_server_may_show_media { false };
+ bool m_window_server_may_show_high_dynamic_range { true };
// Whether the window server shows the canvases and videos of the latest frame above it.
bool m_window_server_shows_media { false };
bool m_frame_without_store_in_flight { false };