1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:57:45 +00:00

LibWeb: Don't encode painting limitations in RecordingPainter API

The current set of stacking context commands do not encode the
information needed to correctly paint the stacking context, instead,
they're based on the limitations of the current CPU renderer.

Stacking contexts should be able to be transformed by an arbitrary
3D transformation matrix, not just scaled from a source to a destination
rect. The `_with_mask()` stacking context also should not be separate
from the regular stacking context.

```c++
push_stacking_context(
	bool semitransparent_or_has_non_identity_transform,
	float opacity, Gfx::FloatRect const& source_rect,
	Gfx::FloatRect const& transformed_destination_rect,
	Gfx::IntPoint const& painter_location);

pop_stacking_context(
	bool semitransparent_or_has_non_identity_transform,
	Gfx::Painter::ScalingMode scaling_mode);

push_stacking_context_with_mask(
	Gfx::IntRect const& paint_rect);

pop_stacking_context_with_mask(
	Gfx::IntRect const& paint_rect,
	RefPtr<Gfx::Bitmap> const& mask_bitmap,
	Gfx::Bitmap::MaskKind mask_kind, float opacity);
```

This patch replaces this APIs with just:

```c++
push_stacking_context(
	float opacity,
        bool is_fixed_position,
        Gfx::IntRect const& source_paintable_rect,
	Gfx::IntPoint post_transform_translation,
	CSS::ImageRendering image_rendering,
	StackingContextTransform transform,
	Optional<StackingContextMask> mask);

pop_stacking_context()
```

And moves the implementation details into the executor, this should
allow future backends to implement stacking contexts without these
limitations.
This commit is contained in:
MacDue 2023-11-18 14:23:59 +00:00 committed by Alexander Kalenik
parent 848b0d9c81
commit 4e04f81626
7 changed files with 189 additions and 253 deletions

View file

@ -266,33 +266,26 @@ void RecordingPainter::restore()
void RecordingPainter::push_stacking_context(PushStackingContextParams params)
{
push_command(PushStackingContext {
.semitransparent_or_has_non_identity_transform = params.semitransparent_or_has_non_identity_transform,
.has_fixed_position = params.has_fixed_position,
.opacity = params.opacity,
.source_rect = state().translation.map(params.source_rect),
.transformed_destination_rect = state().translation.map(params.transformed_destination_rect),
.painter_location = state().translation.map(params.painter_location),
});
if (params.has_fixed_position) {
state().translation.set_translation(0, 0);
}
if (params.semitransparent_or_has_non_identity_transform) {
m_state_stack.append(State());
}
.is_fixed_position = params.is_fixed_position,
.source_paintable_rect = params.source_paintable_rect,
// No translations apply to fixed-position stacking contexts.
.post_transform_translation = params.is_fixed_position
? Gfx::IntPoint {}
: state().translation.translation().to_rounded<int>(),
.image_rendering = params.image_rendering,
.transform = {
.origin = params.transform.origin,
.matrix = params.transform.matrix,
},
.mask = params.mask });
m_state_stack.append(State());
}
void RecordingPainter::pop_stacking_context(PopStackingContextParams params)
void RecordingPainter::pop_stacking_context()
{
push_command(PopStackingContext {
.semitransparent_or_has_non_identity_transform = params.semitransparent_or_has_non_identity_transform,
.scaling_mode = params.scaling_mode,
});
if (params.semitransparent_or_has_non_identity_transform) {
m_state_stack.take_last();
}
push_command(PopStackingContext {});
m_state_stack.take_last();
}
void RecordingPainter::paint_progressbar(Gfx::IntRect frame_rect, Gfx::IntRect progress_rect, Palette palette, int min, int max, int value, StringView text)
@ -380,20 +373,6 @@ void RecordingPainter::fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect
{ bottom_left_radius, bottom_left_radius });
}
void RecordingPainter::push_stacking_context_with_mask(Gfx::IntRect paint_rect)
{
push_command(PushStackingContextWithMask { .paint_rect = state().translation.map(paint_rect) });
}
void RecordingPainter::pop_stacking_context_with_mask(RefPtr<Gfx::Bitmap> mask_bitmap, Gfx::Bitmap::MaskKind mask_kind, Gfx::IntRect paint_rect, float opacity)
{
push_command(PopStackingContextWithMask {
.paint_rect = state().translation.map(paint_rect),
.mask_bitmap = mask_bitmap,
.mask_kind = mask_kind,
.opacity = opacity });
}
void RecordingPainter::draw_triangle_wave(Gfx::IntPoint a_p1, Gfx::IntPoint a_p2, Color color, int amplitude, int thickness = 1)
{
push_command(DrawTriangleWave {
@ -463,16 +442,10 @@ void RecordingPainter::execute(PaintingCommandExecutor& executor)
return executor.set_font(command.font);
},
[&](PushStackingContext const& command) {
return executor.push_stacking_context(command.semitransparent_or_has_non_identity_transform, command.opacity, command.source_rect, command.transformed_destination_rect, command.painter_location);
return executor.push_stacking_context(command.opacity, command.is_fixed_position, command.source_paintable_rect, command.post_transform_translation, command.image_rendering, command.transform, command.mask);
},
[&](PopStackingContext const& command) {
return executor.pop_stacking_context(command.semitransparent_or_has_non_identity_transform, command.scaling_mode);
},
[&](PushStackingContextWithMask const& command) {
return executor.push_stacking_context_with_mask(command.paint_rect);
},
[&](PopStackingContextWithMask const& command) {
return executor.pop_stacking_context_with_mask(command.paint_rect, command.mask_bitmap, command.mask_kind, command.opacity);
[&](PopStackingContext const&) {
return executor.pop_stacking_context();
},
[&](PaintLinearGradient const& command) {
return executor.paint_linear_gradient(command.gradient_rect, command.linear_gradient_data);