From cbd566a3543d5ad50db3b68890ff23f76ca3b4bd Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Mon, 10 Jun 2024 02:58:32 +0300 Subject: [PATCH] LibWeb+WebContent: Move PageClient::paint() into TraversableNavigable This way we leak less LibWeb implementation details into WebContent. --- .../LibWeb/HTML/TraversableNavigable.cpp | 38 ++++++++++++++++++ .../LibWeb/HTML/TraversableNavigable.h | 3 ++ Userland/Libraries/LibWeb/Page/Page.h | 13 +++++++ Userland/Services/WebContent/PageClient.cpp | 39 +++---------------- 4 files changed, 60 insertions(+), 33 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp index aec597347a7..f9cfb02379d 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -16,8 +17,13 @@ #include #include #include +#include #include +#ifdef HAS_ACCELERATED_GRAPHICS +# include +#endif + namespace Web::HTML { JS_DEFINE_ALLOCATOR(TraversableNavigable); @@ -1167,4 +1173,36 @@ JS::GCPtr TraversableNavigable::currently_focused_area() return candidate; } +void TraversableNavigable::paint(Web::DevicePixelRect const& content_rect, Gfx::Bitmap& target, Web::PaintOptions paint_options) +{ + Painting::CommandList painting_commands; + Painting::RecordingPainter recording_painter(painting_commands); + + Gfx::IntRect bitmap_rect { {}, content_rect.size().to_type() }; + recording_painter.fill_rect(bitmap_rect, Web::CSS::SystemColor::canvas()); + + Web::HTML::Navigable::PaintConfig paint_config; + paint_config.paint_overlay = paint_options.paint_overlay == Web::PaintOptions::PaintOverlay::Yes; + paint_config.should_show_line_box_borders = paint_options.should_show_line_box_borders; + paint_config.has_focus = paint_options.has_focus; + record_painting_commands(recording_painter, paint_config); + + if (paint_options.use_gpu_painter) { +#ifdef HAS_ACCELERATED_GRAPHICS + Web::Painting::CommandExecutorGPU painting_command_executor(*paint_options.accelerated_graphics_context, target); + painting_commands.execute(painting_command_executor); +#else + static bool has_warned_about_configuration = false; + + if (!has_warned_about_configuration) { + warnln("\033[31;1mConfigured to use GPU painter, but current platform does not have accelerated graphics\033[0m"); + has_warned_about_configuration = true; + } +#endif + } else { + Web::Painting::CommandExecutorCPU painting_command_executor(target, paint_options.use_experimental_cpu_transform_support); + painting_commands.execute(painting_command_executor); + } +} + } diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h index e254026aa29..8b68121366b 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h @@ -11,6 +11,7 @@ #include #include #include +#include namespace Web::HTML { @@ -84,6 +85,8 @@ public: [[nodiscard]] JS::GCPtr currently_focused_area(); + void paint(Web::DevicePixelRect const&, Gfx::Bitmap&, Web::PaintOptions); + private: TraversableNavigable(JS::NonnullGCPtr); diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index 55c14f99ee0..5cb5e18436f 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -39,6 +39,10 @@ #include #include +#ifdef HAS_ACCELERATED_GRAPHICS +# include +#endif + namespace Web { class PageClient; @@ -249,6 +253,15 @@ struct PaintOptions { }; PaintOverlay paint_overlay { PaintOverlay::Yes }; + bool should_show_line_box_borders { false }; + bool has_focus { false }; + + bool use_gpu_painter { false }; + bool use_experimental_cpu_transform_support { false }; + +#ifdef HAS_ACCELERATED_GRAPHICS + AccelGfx::Context* accelerated_graphics_context { nullptr }; +#endif }; class PageClient : public JS::Cell { diff --git a/Userland/Services/WebContent/PageClient.cpp b/Userland/Services/WebContent/PageClient.cpp index 57226d00d99..c91cd97ae53 100644 --- a/Userland/Services/WebContent/PageClient.cpp +++ b/Userland/Services/WebContent/PageClient.cpp @@ -7,22 +7,17 @@ */ #include -#include #include #include #include -#include #include #include #include -#include #include #include #include -#include #include #include -#include #include #include #include @@ -203,34 +198,12 @@ void PageClient::paint_next_frame() void PageClient::paint(Web::DevicePixelRect const& content_rect, Gfx::Bitmap& target, Web::PaintOptions paint_options) { - Web::Painting::CommandList painting_commands; - Web::Painting::RecordingPainter recording_painter(painting_commands); - - Gfx::IntRect bitmap_rect { {}, content_rect.size().to_type() }; - recording_painter.fill_rect(bitmap_rect, Web::CSS::SystemColor::canvas()); - - Web::HTML::Navigable::PaintConfig paint_config; - paint_config.paint_overlay = paint_options.paint_overlay == Web::PaintOptions::PaintOverlay::Yes; - paint_config.should_show_line_box_borders = m_should_show_line_box_borders; - paint_config.has_focus = m_has_focus; - page().top_level_traversable()->record_painting_commands(recording_painter, paint_config); - - if (s_use_gpu_painter) { -#ifdef HAS_ACCELERATED_GRAPHICS - Web::Painting::CommandExecutorGPU painting_command_executor(*m_accelerated_graphics_context, target); - painting_commands.execute(painting_command_executor); -#else - static bool has_warned_about_configuration = false; - - if (!has_warned_about_configuration) { - warnln("\033[31;1mConfigured to use GPU painter, but current platform does not have accelerated graphics\033[0m"); - has_warned_about_configuration = true; - } -#endif - } else { - Web::Painting::CommandExecutorCPU painting_command_executor(target, s_use_experimental_cpu_transform_support); - painting_commands.execute(painting_command_executor); - } + paint_options.should_show_line_box_borders = m_should_show_line_box_borders; + paint_options.has_focus = m_has_focus; + paint_options.accelerated_graphics_context = m_accelerated_graphics_context.ptr(); + paint_options.use_gpu_painter = s_use_gpu_painter; + paint_options.use_experimental_cpu_transform_support = s_use_experimental_cpu_transform_support; + page().top_level_traversable()->paint(content_rect, target, paint_options); } void PageClient::set_viewport_size(Web::DevicePixelSize const& size)