LibWeb/Painting: Add SaveLayer command

This adds a command for saving the current layer of the canvas.
This is useful for painting content onto a blank background in
isolation and later compositing it onto the canvas.
This commit is contained in:
Glenn Skrzypczak 2025-03-20 15:25:28 +01:00 committed by Sam Atkins
commit 1898643ba4
Notes: github-actions[bot] 2025-03-28 09:42:13 +00:00
7 changed files with 17 additions and 0 deletions

View file

@ -100,6 +100,7 @@ struct DrawRepeatedImmutableBitmap {
}; };
struct Save { }; struct Save { };
struct SaveLayer { };
struct Restore { }; struct Restore { };
struct Translate { struct Translate {
@ -453,6 +454,7 @@ using Command = Variant<
DrawScaledImmutableBitmap, DrawScaledImmutableBitmap,
DrawRepeatedImmutableBitmap, DrawRepeatedImmutableBitmap,
Save, Save,
SaveLayer,
Restore, Restore,
Translate, Translate,
AddClipRect, AddClipRect,

View file

@ -97,6 +97,7 @@ void DisplayListPlayer::execute(DisplayList& display_list)
else HANDLE_COMMAND(DrawRepeatedImmutableBitmap, draw_repeated_immutable_bitmap) else HANDLE_COMMAND(DrawRepeatedImmutableBitmap, draw_repeated_immutable_bitmap)
else HANDLE_COMMAND(AddClipRect, add_clip_rect) else HANDLE_COMMAND(AddClipRect, add_clip_rect)
else HANDLE_COMMAND(Save, save) else HANDLE_COMMAND(Save, save)
else HANDLE_COMMAND(SaveLayer, save_layer)
else HANDLE_COMMAND(Restore, restore) else HANDLE_COMMAND(Restore, restore)
else HANDLE_COMMAND(Translate, translate) else HANDLE_COMMAND(Translate, translate)
else HANDLE_COMMAND(PushStackingContext, push_stacking_context) else HANDLE_COMMAND(PushStackingContext, push_stacking_context)

View file

@ -40,6 +40,7 @@ private:
virtual void draw_scaled_immutable_bitmap(DrawScaledImmutableBitmap const&) = 0; virtual void draw_scaled_immutable_bitmap(DrawScaledImmutableBitmap const&) = 0;
virtual void draw_repeated_immutable_bitmap(DrawRepeatedImmutableBitmap const&) = 0; virtual void draw_repeated_immutable_bitmap(DrawRepeatedImmutableBitmap const&) = 0;
virtual void save(Save const&) = 0; virtual void save(Save const&) = 0;
virtual void save_layer(SaveLayer const&) = 0;
virtual void restore(Restore const&) = 0; virtual void restore(Restore const&) = 0;
virtual void translate(Translate const&) = 0; virtual void translate(Translate const&) = 0;
virtual void add_clip_rect(AddClipRect const&) = 0; virtual void add_clip_rect(AddClipRect const&) = 0;

View file

@ -177,6 +177,12 @@ void DisplayListPlayerSkia::save(Save const&)
canvas.save(); canvas.save();
} }
void DisplayListPlayerSkia::save_layer(SaveLayer const&)
{
auto& canvas = surface().canvas();
canvas.saveLayer(nullptr, nullptr);
}
void DisplayListPlayerSkia::restore(Restore const&) void DisplayListPlayerSkia::restore(Restore const&)
{ {
auto& canvas = surface().canvas(); auto& canvas = surface().canvas();

View file

@ -28,6 +28,7 @@ private:
void draw_repeated_immutable_bitmap(DrawRepeatedImmutableBitmap const&) override; void draw_repeated_immutable_bitmap(DrawRepeatedImmutableBitmap const&) override;
void add_clip_rect(AddClipRect const&) override; void add_clip_rect(AddClipRect const&) override;
void save(Save const&) override; void save(Save const&) override;
void save_layer(SaveLayer const&) override;
void restore(Restore const&) override; void restore(Restore const&) override;
void translate(Translate const&) override; void translate(Translate const&) override;
void push_stacking_context(PushStackingContext const&) override; void push_stacking_context(PushStackingContext const&) override;

View file

@ -280,6 +280,11 @@ void DisplayListRecorder::save()
append(Save {}); append(Save {});
} }
void DisplayListRecorder::save_layer()
{
append(SaveLayer {});
}
void DisplayListRecorder::restore() void DisplayListRecorder::restore()
{ {
append(Restore {}); append(Restore {});

View file

@ -114,6 +114,7 @@ public:
void pop_scroll_frame_id(); void pop_scroll_frame_id();
void save(); void save();
void save_layer();
void restore(); void restore();
struct PushStackingContextParams { struct PushStackingContextParams {