LibWeb+WebContent: Move PageClient::paint() into TraversableNavigable

This way we leak less LibWeb implementation details into WebContent.
This commit is contained in:
Aliaksandr Kalenik 2024-06-10 02:58:32 +03:00 committed by Alexander Kalenik
parent c7133faf26
commit cbd566a354
Notes: sideshowbarker 2024-07-17 03:03:44 +09:00
4 changed files with 60 additions and 33 deletions

View file

@ -6,6 +6,7 @@
#include <AK/QuickSort.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/CSS/SystemColor.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/BrowsingContextGroup.h>
#include <LibWeb/HTML/DocumentState.h>
@ -16,8 +17,13 @@
#include <LibWeb/HTML/TraversableNavigable.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/Painting/CommandExecutorCPU.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
#ifdef HAS_ACCELERATED_GRAPHICS
# include <LibWeb/Painting/CommandExecutorGPU.h>
#endif
namespace Web::HTML {
JS_DEFINE_ALLOCATOR(TraversableNavigable);
@ -1167,4 +1173,36 @@ JS::GCPtr<DOM::Node> 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<int>() };
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);
}
}
}

View file

@ -11,6 +11,7 @@
#include <LibWeb/HTML/NavigationType.h>
#include <LibWeb/HTML/SessionHistoryTraversalQueue.h>
#include <LibWeb/HTML/VisibilityState.h>
#include <LibWeb/Page/Page.h>
namespace Web::HTML {
@ -84,6 +85,8 @@ public:
[[nodiscard]] JS::GCPtr<DOM::Node> currently_focused_area();
void paint(Web::DevicePixelRect const&, Gfx::Bitmap&, Web::PaintOptions);
private:
TraversableNavigable(JS::NonnullGCPtr<Page>);

View file

@ -39,6 +39,10 @@
#include <LibWeb/PixelUnits.h>
#include <LibWeb/UIEvents/KeyCode.h>
#ifdef HAS_ACCELERATED_GRAPHICS
# include <LibAccelGfx/Context.h>
#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 {

View file

@ -7,22 +7,17 @@
*/
#include <LibGfx/ShareableBitmap.h>
#include <LibGfx/SystemTheme.h>
#include <LibJS/Console.h>
#include <LibJS/Runtime/ConsoleObject.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/CSS/SystemColor.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/DOM/Attr.h>
#include <LibWeb/DOM/NamedNodeMap.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/Scripting/ClassicScript.h>
#include <LibWeb/HTML/TraversableNavigable.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Painting/CommandExecutorCPU.h>
#include <LibWeb/Painting/PaintableBox.h>
#include <LibWeb/Painting/ViewportPaintable.h>
#include <LibWeb/Platform/Timer.h>
#include <LibWebView/Attribute.h>
#include <WebContent/ConnectionFromClient.h>
#include <WebContent/PageClient.h>
@ -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<int>() };
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)