mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 12:27: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
|
@ -64,14 +64,23 @@ static Gfx::Bitmap::MaskKind mask_type_to_gfx_mask_kind(CSS::MaskType mask_type)
|
|||
}
|
||||
}
|
||||
|
||||
void SVGGraphicsPaintable::apply_mask(PaintContext& context, Gfx::Bitmap& target, CSSPixelRect const& masking_area) const
|
||||
Optional<Gfx::Bitmap::MaskKind> SVGGraphicsPaintable::get_mask_type() const
|
||||
{
|
||||
auto const& graphics_element = verify_cast<SVG::SVGGraphicsElement const>(*dom_node());
|
||||
auto mask = graphics_element.mask();
|
||||
if (!mask)
|
||||
return {};
|
||||
return mask_type_to_gfx_mask_kind(mask->layout_node()->computed_values().mask_type());
|
||||
}
|
||||
|
||||
RefPtr<Gfx::Bitmap> SVGGraphicsPaintable::calculate_mask(PaintContext& context, CSSPixelRect const& masking_area) const
|
||||
{
|
||||
auto const& graphics_element = verify_cast<SVG::SVGGraphicsElement const>(*dom_node());
|
||||
auto mask = graphics_element.mask();
|
||||
VERIFY(mask);
|
||||
if (mask->mask_content_units() != SVG::MaskContentUnits::UserSpaceOnUse) {
|
||||
dbgln("SVG: maskContentUnits=objectBoundingBox is not supported");
|
||||
return;
|
||||
return {};
|
||||
}
|
||||
auto mask_rect = context.enclosing_device_rect(masking_area);
|
||||
RefPtr<Gfx::Bitmap> mask_bitmap = {};
|
||||
|
@ -79,20 +88,18 @@ void SVGGraphicsPaintable::apply_mask(PaintContext& context, Gfx::Bitmap& target
|
|||
auto& mask_paintable = static_cast<PaintableBox const&>(*mask->layout_node()->paintable());
|
||||
auto mask_bitmap_or_error = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, mask_rect.size().to_type<int>());
|
||||
if (mask_bitmap_or_error.is_error())
|
||||
return;
|
||||
return {};
|
||||
mask_bitmap = mask_bitmap_or_error.release_value();
|
||||
{
|
||||
Gfx::Painter painter(*mask_bitmap);
|
||||
RecordingPainter painter;
|
||||
painter.translate(-mask_rect.location().to_type<int>());
|
||||
auto paint_context = context.clone(painter);
|
||||
paint_context.set_svg_transform(graphics_element.get_transform());
|
||||
StackingContext::paint_node_as_stacking_context(mask_paintable, paint_context);
|
||||
painter.execute(*mask_bitmap);
|
||||
}
|
||||
}
|
||||
if (mask_bitmap)
|
||||
target.apply_mask(*mask_bitmap,
|
||||
mask_type_to_gfx_mask_kind(mask->layout_node()->computed_values().mask_type()));
|
||||
return;
|
||||
return mask_bitmap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue