Commit graph

379 commits

Author SHA1 Message Date
Jelle Raaijmakers
d352c4673c LibWeb: Pass sizes instead of rects to to_gfx_scaling_mode()
Position is irrelevant when determining the right scaling mode. No
functional changes.
2025-11-12 15:59:01 +01:00
Jelle Raaijmakers
7544066c0c LibWeb: Scale blur filter's radius by device pixel scale
The blur filter's effect was reduced on higher DPI displays.
2025-11-12 15:59:01 +01:00
Psychpsyo
eb21ea890c LibWeb: Implement CSS perspective property 2025-11-12 00:41:14 +01:00
Psychpsyo
e44a97e508 LibWeb: Pass 3D transforms to Skia 2025-11-12 00:41:14 +01:00
Callum Law
7a5b948b5b LibWeb: Resolve more calculated values in ComputedProperties
We simplify these at style computation time so there is no need to
maintain them as {Number|Length}OrCalculated

Reduces the time spent in `Length::ResolutionContext::for_layout_node`
from 3.3% to 0.4% when loading
https://en.wikipedia.org/wiki/2023_in_American_television
2025-11-10 12:11:36 +01:00
Luke Wilde
82bd3d3891 LibWeb: Avoid invoking Trusted Types where avoidable
Prevents observably calling Trusted Types, which can run arbitrary JS,
cause crashes due to use of MUST and allow arbitrary JS to modify
internal elements.
2025-11-06 11:43:06 -05:00
Andreas Kling
4ed6eac5be LibWeb: Use new DecodedImageData::paint() API in ImagePaintable 2025-11-05 09:11:49 +01:00
Aliaksandr Kalenik
ed921b66f5 LibGfx+LibWeb: Delete unused Line class and Rect methods 2025-11-04 23:16:02 +01:00
Zaggy1024
f3a2207bc8 LibWeb: Correct the early exit condition in AudioPaintable::paint()
We're not painting controls for audio elements that are supposed to
have them!
2025-11-03 13:25:02 -06:00
Zaggy1024
e9495d0ba0 LibWeb: Implement media element seeking through PlaybackManager
Including the behavior to conditionally seek forward when fast seeking!
2025-10-27 17:28:49 -07:00
Zaggy1024
6caa2f99aa LibMedia+LibWeb: Rewrite PlaybackManager using the provider/sink model
With this commit, all PlaybackManager can do is autoplay a file from
start to finish, with no pausing or seeking functionality.

All audio playback functionality has been removed from HTMLMediaElement
and HTMLAudioElement in anticipation of PlaybackManager taking that
over, for both audio-only and audio/video.
2025-10-27 17:28:49 -07:00
Jelle Raaijmakers
6f50c35d68 LibWeb: Misc. cleanup of code
Some things I came across while working on a bugfix. No functional
changes.
2025-10-27 16:42:27 -07:00
Jelle Raaijmakers
e4de6c0d05 LibWeb: Return early if scroll offset is zero
No need to calculate scroll offsets and translate update list commands
if the cumulative offset was zero to begin with.
2025-10-27 16:42:27 -07:00
Jelle Raaijmakers
c0d08b68af LibWeb: Dump path_bounding_rect for FillPath
This makes it easier to differentiate between FillPath commands in the
display list output.
2025-10-27 16:42:27 -07:00
Jelle Raaijmakers
f8c4043460 LibWeb: Repeat shader for repeating linear gradient
We implemented repeating linear gradients by expanding a vector of color
stops until the entire range was covered. This is both a bit wasteful
and caused Skia to draw corrupted gradients to screen whenever the total
amount of color stops and positions exceeded 127.

Instead of doing that, use the original color stops for the shader and
repeat it instead of clamping it. We need to do a bit of math to project
positions correctly, but after that the shader repeats itself nicely.

While we're here, calculate the gradient's length and the center point
as floats instead of ints, yielding a slight but noticeable improvement
in gradient rendering (see the diff on the zig zag pattern in
css-gradients.html for an example of this).
2025-10-22 10:45:18 +02:00
Jelle Raaijmakers
e6ddc995a7 LibWeb: Remove unused include from GradientData.h 2025-10-22 10:45:18 +02:00
Jelle Raaijmakers
868c29545a LibWeb: Skip one single positive linear gradient color stop repeat
We prime `color_stop_list_with_expanded_repeat` with the input
`color_stop_list`, so we don't actually need to copy the stops for the
first iteration. This didn't result in graphical glitches, but these
entries were unnecessary irregardless.
2025-10-22 10:45:18 +02:00
Psychpsyo
80b629578e LibWeb: Fix partially selecting non-text nodes
Steps 4 and 5 were swapped since marking all the nodes between the start
and end of the selection now also marks the end node as full, even if it
should be marked as End.
There could be extra logic to avoid marking it if it is a text node, but
this seems easier.

As a whole, this fixes partially selected non-text nodes. In such cases,
where the selection starts or ends inside a node with descendants, it is
impossible to just select from the start node to the end node since that
would select all descendants of the start node and none of the end node.
Previously, this was only half considered and only if the start node was
a descendant of the end node.
2025-10-21 10:23:10 +01:00
Rocco Corsi
edb60e38bd LibWeb: Update painting backing stores in all cases
To consistently update the backing stores in reallocate_backing_stores()
the variables storing the backing stores need to be set to nullptr at
the start so that they are properly update later on near the end of the
function.
2025-10-21 09:17:53 +02:00
Luke Wilde
eeb5446c1b LibWeb: Avoid including Navigable.h in headers
This greatly reduces how much is recompiled when changing Navigable.h,
from >1000 to 82.
2025-10-20 10:16:55 +01:00
Tim Ledbetter
34857ba554 LibWeb: Apply dithering when painting gradients 2025-10-19 16:53:00 +02:00
Andreas Kling
dfa796a4e4 LibJS+LibWeb: Use GC::Weak instead of AK::WeakPtr for GC-allocated types
This makes some common types like JS::Object smaller (by 8 bytes) and
yields a minor speed improvement on many benchmarks.
2025-10-17 17:22:16 +02:00
Aliaksandr Kalenik
4853e2ffb1 LibWeb: Don't reach into layout node to check if paintable is SVG 2025-10-14 11:23:29 +02:00
Aliaksandr Kalenik
881ef21d40 LibWeb: Get rid of SVGPathPaintable::layout_box()
It was used exclusively to get corresponding DOM node pointer, which is
unnecessary indirection as Paintable owns the DOM node pointer directly.
2025-10-14 11:23:29 +02:00
Aliaksandr Kalenik
f706c883eb LibWeb: Don't reach into layout node to check if Paintable is positioned
We copy this information into Paintable, so it could be taken directly
from there.
2025-10-14 11:23:29 +02:00
Aliaksandr Kalenik
9e838cffb4 LibWeb: Copy "is inert" attribute into Paintable
...instead of reaching into DOM tree during hit-testing in order to
figure out if an element is inert. This is a part of the effert to make
possible running hit-testing solely based on data contained by the
paintable tree.
2025-10-14 11:23:29 +02:00
Aliaksandr Kalenik
81aeee3fb4 LibWeb: Get rid of PaintableBox::is_viewport()
This function used layout node pointer to check if it's corresponding to
viewport. There is no need for that, since `is_viewport_paintable()`
does exactly the same check without going through layout node.
2025-10-14 11:23:29 +02:00
Aliaksandr Kalenik
9e3e581e14 LibWeb: Delete unused m_combined_css_transform from PaintableBox 2025-10-10 16:58:51 +02:00
Aliaksandr Kalenik
72aaef5a0f LibWeb: Delete non-const layout_node_with_style_and_box_metrics()
...from PaintableBox. It was used exclusively to go to corresponding DOM
node which could be done via direct DOM node pointer owned by paintable.
2025-10-10 16:58:51 +02:00
Aliaksandr Kalenik
9862d8b4a6 LibWeb: Implement pinch-to-zoom support
Adds pinch event handling that adjusts the VisualViewport scale and
offset. VisualViewport's (offset, scale) is then used to construct a
transformation matrix which is applied before display list execution.
2025-10-10 15:37:45 +02:00
Aliaksandr Kalenik
b786935169 LibWeb: Delete CheckBoxPaintable::layout_box()
No need for this method when we could reach into DOM node directly from
Paintable.
2025-10-10 09:03:39 +02:00
Aliaksandr Kalenik
38ca745a59 LibWeb: Delete CanvasPaintable::layout_box()
No need for this method when we could reach into DOM node directly from
Paintable.
2025-10-10 09:03:39 +02:00
Aliaksandr Kalenik
d3f40e9a72 LibWeb: Delete AudioPaintable::layout_box()
No need for this method when we could reach into DOM node directly from
Paintable.
2025-10-10 09:03:39 +02:00
Aliaksandr Kalenik
33a8fbd22c LibWeb: Delete unused SVGGraphicsPaintable::layout_box() 2025-10-10 09:03:39 +02:00
Aliaksandr Kalenik
3675560804 LibWeb: Delete unused SVGSVGPaintable::layout_box() 2025-10-10 09:03:39 +02:00
Aliaksandr Kalenik
2c2584ee99 LibWeb: Delete VideoPaintable::layout_box()
No need for this method when we could reach into DOM node directly from
Paintable.
2025-10-10 09:03:39 +02:00
Aliaksandr Kalenik
5c699e1a45 LibWeb: Delete NavigableContainerViewportPaintable::layout_box()
No need for this method when we could reach into DOM node directly from
Paintable.
2025-10-10 09:03:39 +02:00
Luke Wilde
adeedabf54 LibWeb: Don't class mousewheel as handled if scroll offset isn't updated
Before this change, you could only scroll the current hovered scroll
container, even if it was at the beginning or end and thus having no
effect.

Now, if it doesn't update, it will not be classed as handled and will
move onto the next scroll container.
2025-10-07 19:43:07 +02:00
Aliaksandr Kalenik
86505a7de4 LibWeb: Remove unnecessary adjustments for transforms in hit_test()
of `PaintableBox` and `PaintableWithLines`.

If we ended up with non-identity transform in `hit_test()` of PB or PWL
and have to account for transforms, means we forgot to skip stacking
context while iterating through children.

- Add missing check to skip paintable that eastablishing a stacking
  context in `PaintableBox::hit_test_children()`
- Otherwise it mostly reverts changes done by 4070f5a7e
2025-10-03 21:49:59 +02:00
Aliaksandr Kalenik
086ef9e339 LibWeb: Delete unused Paintable::combined_css_transform() 2025-09-26 20:11:32 +02:00
Andreas Kling
321809320b LibWeb+LibGfx: Remove Path::close_all_subpaths()
As it turns out, SkPath already behaves the way we need for SVG and HTML
canvas elements. Less work for us, yay! This removes a 5% item from the
profile when scrolling on https://imdb.com/

Note that there's a tiny screenshot test expectation change due to
minor antialiasing differences when we no longer do our redundant
subpath modifications.
2025-09-25 21:42:52 +02:00
Psychpsyo
2fcacd21f5 LibWeb: Compute bounds for paint-contained stacking contexts
This makes it so that the bounds for any paint-contained stacking
context are not derived from its children, but rather just set to
the rectangle that they will be clipped to anyways due to the paint
containment. Should make rendering faster on pages that use paint
containment.
2025-09-25 15:10:10 +02:00
Aliaksandr Kalenik
90432f35d5 LibWeb: Call saveLayer() after applying matrix in PushStackingContext
This is required because bounding rect used in `saveLayer()` is computed
in stacking context's coordinate space.

Fixes regression introduced in ba2926f
2025-09-25 04:39:26 +02:00
Andreas Kling
ec73299398 LibWeb: Resolve paint-only properties in SVGPathPaintable once
Instead of resolving some viewport-relative sizes on every paint, we now
do them just once in paint-only property update.

This takes SVGPathPaintable::paint() from 15% to 8% in the profile when
scrolling on https://imdb.com/
2025-09-24 23:59:41 +02:00
Andreas Kling
eff9989aeb LibWeb: Only update paint-only properties in affected subtrees
Before this change, we always updated paint-only properties for every
single paintable after layout or style changes.

This could get very expensive in large documents, so this patch makes
it something we can do partially based on "repaint" invalidations.

This cuts down time spent in paint-only property update when scrolling
https://imdb.com/ from 19% to 5%.
2025-09-24 23:59:41 +02:00
Andreas Kling
beb70d2112 LibWeb: Add Paintable::debug_description()
I keep reimplementing this function over and over when debugging stuff,
so let's just have it around.
2025-09-24 23:59:41 +02:00
Aliaksandr Kalenik
ba2926f8b3 LibWeb: Calculate and use bounds for "simple" stacking contexts
Teach the display list executor to derive a bounding rectangle for
stacking contexts whose inner commands can all report bounds, that is,
most contexts without nested stacking contexts.

This yields a large performance improvement on https://tc39.es/ecma262/
where the display list contains thousands of groups like:
```
PushStackingContext blending=Multiply
    DrawGlyphRun
PopStackingContext
```
Previously, `PushStackingContext` triggered an unbounded `saveLayer()`
even when the glyph run lies wholly outside the viewport. With this
change, we (1) cull stacking contexts that fall outside the viewport and
(2) provide bounds to `saveLayer()` when they are visible.

With this change rendering thread goes from 70% to 1% in profiles of
https://tc39.es/ecma262/. Also makes a huge performance difference on
Discord.
2025-09-24 22:11:24 +02:00
zac
e96122a58c LibWeb: Remove redundant for_each_fragment method in PaintableBox 2025-09-24 12:33:17 +01:00
Aliaksandr Kalenik
9bbc1cd618 LibWeb: Check if transform is identity instead of has_css_transform()
...in clip and scroll frames calculation algorithm.

Fix a regression from 719a50c where display-list recording disagreed
with the clipping logic about whether a stacking context is transformed.
`has_css_transform()` returns true whenever the computed transform is
not `none`, which differs from an identity-matrix check. These yield
different results for cases like `translate(0, 0)`.
2025-09-23 23:35:19 +02:00
Aliaksandr Kalenik
719a50c9bf LibWeb: Don't emit Push{Pop}StackingContext without visible effect
Before this change we would emit PushStackingContext/PopStackingContext
display list items regardless of whether the stacking context had any
transform/opacity/clip effects.

Display list size on https://x.com/ladybirdbrowser is reduced from ~2700
to ~800 items.
2025-09-23 19:05:01 +02:00