1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:38:13 +00:00

LibWeb: Introduce RecordingPainter to serialize painting commands

This modification introduces a new layer to the painting process. The
stacking context traversal no longer immediately calls the
Gfx::Painter methods. Instead, it writes serialized painting commands
into newly introduced RecordingPainter. Created list of commands is
executed later to produce resulting bitmap.

Producing painting command list will make it easier to add new
optimizations:
- It's simpler to check if the painting result is not visible in the
  viewport at the command level rather than during stacking context
  traversal.
- Run painting in a separate thread. The painting thread can process
  serialized painting commands, while the main thread can work on the
  next paintable tree and safely invalidate the previous one.
- As we consider GPU-accelerated painting support, it would be easier
  to back each painting command rather than constructing an alternative
  for the entire Gfx::Painter API.
This commit is contained in:
Aliaksandr Kalenik 2023-10-15 04:27:48 +02:00 committed by Andreas Kling
parent 8ebb4e8047
commit 063e66cae9
49 changed files with 1970 additions and 441 deletions

View file

@ -11,15 +11,16 @@
#include <LibGfx/Forward.h>
#include <LibGfx/Palette.h>
#include <LibGfx/Rect.h>
#include <LibWeb/Painting/RecordingPainter.h>
#include <LibWeb/PixelUnits.h>
namespace Web {
class PaintContext {
public:
PaintContext(Gfx::Painter& painter, Palette const& palette, double device_pixels_per_css_pixel);
PaintContext(Painting::RecordingPainter& painter, Palette const& palette, double device_pixels_per_css_pixel);
Gfx::Painter& painter() const { return m_painter; }
Painting::RecordingPainter& painter() const { return m_painter; }
Palette const& palette() const { return m_palette; }
bool should_show_line_box_borders() const { return m_should_show_line_box_borders; }
@ -29,8 +30,6 @@ public:
void set_device_viewport_rect(DevicePixelRect const& rect) { m_device_viewport_rect = rect; }
CSSPixelRect css_viewport_rect() const;
[[nodiscard]] bool would_be_fully_clipped_by_painter(DevicePixelRect) const;
bool has_focus() const { return m_focus; }
void set_has_focus(bool focus) { m_focus = focus; }
@ -58,7 +57,7 @@ public:
CSSPixelSize scale_to_css_size(DevicePixelSize) const;
CSSPixelRect scale_to_css_rect(DevicePixelRect) const;
PaintContext clone(Gfx::Painter& painter) const
PaintContext clone(Painting::RecordingPainter& painter) const
{
auto clone = PaintContext(painter, m_palette, m_device_pixels_per_css_pixel);
clone.m_device_viewport_rect = m_device_viewport_rect;
@ -73,7 +72,7 @@ public:
void translate_scroll_offset_by(CSSPixelPoint offset) { m_scroll_offset.translate_by(offset); }
private:
Gfx::Painter& m_painter;
Painting::RecordingPainter& m_painter;
Palette m_palette;
double m_device_pixels_per_css_pixel { 0 };
DevicePixelRect m_device_viewport_rect;