mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:17:35 +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:
parent
8ebb4e8047
commit
063e66cae9
49 changed files with 1970 additions and 441 deletions
|
@ -16,27 +16,20 @@ enum class CornerClip {
|
|||
Inside
|
||||
};
|
||||
|
||||
class BorderRadiusCornerClipper {
|
||||
class BorderRadiusCornerClipper : public RefCounted<BorderRadiusCornerClipper> {
|
||||
public:
|
||||
enum class UseCachedBitmap {
|
||||
Yes,
|
||||
No
|
||||
};
|
||||
|
||||
static ErrorOr<BorderRadiusCornerClipper> create(PaintContext&, DevicePixelRect const& border_rect, BorderRadiiData const& border_radii, CornerClip corner_clip = CornerClip::Outside, UseCachedBitmap use_cached_bitmap = UseCachedBitmap::Yes);
|
||||
static ErrorOr<NonnullRefPtr<BorderRadiusCornerClipper>> create(CornerRadii const&, DevicePixelRect const& border_rect, BorderRadiiData const& border_radii, CornerClip corner_clip = CornerClip::Outside, UseCachedBitmap use_cached_bitmap = UseCachedBitmap::Yes);
|
||||
|
||||
void sample_under_corners(Gfx::Painter& page_painter);
|
||||
void blit_corner_clipping(Gfx::Painter& page_painter);
|
||||
|
||||
private:
|
||||
using CornerRadius = Gfx::AntiAliasingPainter::CornerRadius;
|
||||
struct CornerData {
|
||||
struct CornerRadii {
|
||||
CornerRadius top_left;
|
||||
CornerRadius top_right;
|
||||
CornerRadius bottom_right;
|
||||
CornerRadius bottom_left;
|
||||
} corner_radii;
|
||||
CornerRadii corner_radii;
|
||||
struct CornerLocations {
|
||||
DevicePixelPoint top_left;
|
||||
DevicePixelPoint top_right;
|
||||
|
@ -48,44 +41,30 @@ private:
|
|||
DevicePixelSize corner_bitmap_size;
|
||||
} m_data;
|
||||
|
||||
NonnullRefPtr<Gfx::Bitmap> m_corner_bitmap;
|
||||
bool m_has_sampled { false };
|
||||
CornerClip m_corner_clip { false };
|
||||
|
||||
BorderRadiusCornerClipper(CornerData corner_data, NonnullRefPtr<Gfx::Bitmap> corner_bitmap, CornerClip corner_clip)
|
||||
: m_data(move(corner_data))
|
||||
, m_corner_bitmap(corner_bitmap)
|
||||
, m_corner_clip(corner_clip)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
NonnullRefPtr<Gfx::Bitmap> m_corner_bitmap;
|
||||
bool m_has_sampled { false };
|
||||
CornerClip m_corner_clip { false };
|
||||
};
|
||||
|
||||
struct ScopedCornerRadiusClip {
|
||||
ScopedCornerRadiusClip(PaintContext& context, Gfx::Painter& painter, DevicePixelRect const& border_rect, BorderRadiiData const& border_radii, CornerClip corner_clip = CornerClip::Outside, BorderRadiusCornerClipper::UseCachedBitmap use_cached_bitmap = BorderRadiusCornerClipper::UseCachedBitmap::Yes)
|
||||
: m_painter(painter)
|
||||
{
|
||||
if (border_radii.has_any_radius()) {
|
||||
auto clipper = BorderRadiusCornerClipper::create(context, border_rect, border_radii, corner_clip, use_cached_bitmap);
|
||||
if (!clipper.is_error()) {
|
||||
m_corner_clipper = clipper.release_value();
|
||||
m_corner_clipper->sample_under_corners(m_painter);
|
||||
}
|
||||
}
|
||||
}
|
||||
ScopedCornerRadiusClip(PaintContext& context, DevicePixelRect const& border_rect, BorderRadiiData const& border_radii, CornerClip corner_clip = CornerClip::Outside, BorderRadiusCornerClipper::UseCachedBitmap use_cached_bitmap = BorderRadiusCornerClipper::UseCachedBitmap::Yes);
|
||||
|
||||
~ScopedCornerRadiusClip()
|
||||
{
|
||||
if (m_corner_clipper.has_value()) {
|
||||
m_corner_clipper->blit_corner_clipping(m_painter);
|
||||
}
|
||||
}
|
||||
~ScopedCornerRadiusClip();
|
||||
|
||||
AK_MAKE_NONMOVABLE(ScopedCornerRadiusClip);
|
||||
AK_MAKE_NONCOPYABLE(ScopedCornerRadiusClip);
|
||||
|
||||
private:
|
||||
Gfx::Painter& m_painter;
|
||||
Optional<BorderRadiusCornerClipper> m_corner_clipper;
|
||||
PaintContext& m_context;
|
||||
RefPtr<BorderRadiusCornerClipper> m_corner_clipper;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue