1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:37:43 +00:00

LibWeb: Apply stacking context transform in GPU painter

This commit is contained in:
Aliaksandr Kalenik 2023-11-28 19:00:52 +01:00 committed by Andreas Kling
parent aaf54f8cf8
commit 9fa6628efa

View file

@ -90,24 +90,32 @@ CommandResult PaintingCommandExecutorGPU::set_font(Gfx::Font const&)
return CommandResult::Continue; return CommandResult::Continue;
} }
CommandResult PaintingCommandExecutorGPU::push_stacking_context(float opacity, bool is_fixed_position, Gfx::IntRect const& source_paintable_rect, Gfx::IntPoint post_transform_translation, CSS::ImageRendering, StackingContextTransform, Optional<StackingContextMask>) CommandResult PaintingCommandExecutorGPU::push_stacking_context(float opacity, bool is_fixed_position, Gfx::IntRect const& source_paintable_rect, Gfx::IntPoint post_transform_translation, CSS::ImageRendering, StackingContextTransform transform, Optional<StackingContextMask>)
{ {
painter().save(); painter().save();
if (is_fixed_position) { if (is_fixed_position) {
auto const& translation = painter().transform().translation(); auto const& translation = painter().transform().translation();
painter().translate(-translation); painter().translate(-translation);
} }
auto affine_transform = Gfx::extract_2d_affine_transform(transform.matrix);
if (opacity < 1) { if (opacity < 1) {
auto painter = AccelGfx::Painter::create(); auto painter = AccelGfx::Painter::create();
auto canvas = AccelGfx::Canvas::create(source_paintable_rect.size()); auto canvas = AccelGfx::Canvas::create(source_paintable_rect.size());
painter->set_target_canvas(canvas); painter->set_target_canvas(canvas);
painter->translate(-source_paintable_rect.location().to_type<float>()); painter->translate(-source_paintable_rect.location().to_type<float>());
auto source_rect = source_paintable_rect.to_type<float>().translated(-transform.origin);
auto transformed_destination_rect = affine_transform.map(source_rect).translated(transform.origin);
auto destination_rect = transformed_destination_rect.to_rounded<int>();
stacking_contexts.append({ .canvas = canvas, stacking_contexts.append({ .canvas = canvas,
.painter = move(painter), .painter = move(painter),
.opacity = opacity, .opacity = opacity,
.destination = source_paintable_rect }); .destination = destination_rect });
} else { } else {
painter().translate(post_transform_translation.to_type<float>()); painter().translate(affine_transform.translation() + post_transform_translation.to_type<float>());
} }
return CommandResult::Continue; return CommandResult::Continue;
} }