1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 01:47:34 +00:00

LibWeb: Record painting commands in coordinates of stacking context

By storing painting command coordinates relative to the nearest
stacking context we can get rid of the Translate command.

Additionally, this allows us to easily check if the bounding
rectangles of the commands cover or intersect within a stacking
context. This should be useful if we decide to optimize by avoiding
the execution of commands that will be overpainted by the results of
subsequent commands.
This commit is contained in:
Aliaksandr Kalenik 2023-10-24 18:48:27 +02:00 committed by Andreas Kling
parent 311cc7d9b9
commit 4318bcf447
6 changed files with 76 additions and 68 deletions

View file

@ -83,12 +83,6 @@ struct DrawScaledBitmap {
[[nodiscard]] CommandResult execute(CommandExecutionState&) const;
};
struct Translate {
Gfx::IntPoint translation_delta;
[[nodiscard]] CommandResult execute(CommandExecutionState&) const;
};
struct SaveState {
[[nodiscard]] CommandResult execute(CommandExecutionState&) const;
};
@ -367,7 +361,6 @@ using PaintingCommand = Variant<
DrawText,
FillRect,
DrawScaledBitmap,
Translate,
SaveState,
RestoreState,
AddClipRect,
@ -510,6 +503,17 @@ public:
void execute(Gfx::Bitmap&);
RecordingPainter()
{
m_state_stack.append(State());
}
struct State {
Gfx::AffineTransform translation;
};
State& state() { return m_state_stack.last(); }
State const& state() const { return m_state_stack.last(); }
private:
void push_command(PaintingCommand command)
{
@ -517,6 +521,7 @@ private:
}
Vector<PaintingCommand> m_painting_commands;
Vector<State> m_state_stack;
};
class RecordingPainterStateSaver {