Преглед изворни кода

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

This way we leak less LibWeb implementation details into WebContent.
Aliaksandr Kalenik пре 1 година
родитељ
комит
cbd566a354

+ 38 - 0
Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp

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

+ 3 - 0
Userland/Libraries/LibWeb/HTML/TraversableNavigable.h

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

+ 13 - 0
Userland/Libraries/LibWeb/Page/Page.h

@@ -39,6 +39,10 @@
 #include <LibWeb/PixelUnits.h>
 #include <LibWeb/PixelUnits.h>
 #include <LibWeb/UIEvents/KeyCode.h>
 #include <LibWeb/UIEvents/KeyCode.h>
 
 
+#ifdef HAS_ACCELERATED_GRAPHICS
+#    include <LibAccelGfx/Context.h>
+#endif
+
 namespace Web {
 namespace Web {
 
 
 class PageClient;
 class PageClient;
@@ -249,6 +253,15 @@ struct PaintOptions {
     };
     };
 
 
     PaintOverlay paint_overlay { PaintOverlay::Yes };
     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 {
 class PageClient : public JS::Cell {

+ 6 - 33
Userland/Services/WebContent/PageClient.cpp

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