Commit graph

594 commits

Author SHA1 Message Date
Tim Ledbetter
e1ff1e2095 LibWeb: Implement CanvasPattern.setTransform()
This method applies the given transformation matrix to a pattern.
2025-10-27 16:41:02 -07:00
Tim Ledbetter
8854bb62c6 LibGfx: Use CSS sRGB serialization for canvas fill styles 2025-10-26 18:55:22 +01:00
Tim Ledbetter
ebd802f6fc LibWeb+LibGfx: Move CSS sRGB color serialization function to LibGfx 2025-10-26 18:55:22 +01:00
Jelle Raaijmakers
86725de23d LibGfx: Use correct include path for SkImage.h
Fixes our flatpak builds.
2025-10-24 12:44:24 +02:00
Andreas Kling
4f684bb4c9 LibGfx: Don't create AnonymousBuffer for each bitmap in BitmapSequence
When decoding a BitmapSequence received over IPC, we were creating an
AnonymousBuffer for each bitmap and then making a Gfx::Bitmap wrapper
around it.

This was unnecessarily using up one file descriptor per bitmap, and also
wasting a lot of memory for small bitmaps since we always allocated at
least one VM page.

This patch changes the BitmapSequence decoder to use malloc memory
instead, saving file descriptors and using less memory overall.
2025-10-24 08:52:53 +02:00
Tim Ledbetter
017e8a5b8d LibGfx: Add a method to reset a Painter to its initial state 2025-10-23 18:52:36 +02:00
Jelle Raaijmakers
62ae4e878f LibWeb: Implement support for drawing with CanvasPattern
We already had the API, but drawing to the canvas was not affected by
any created CanvasPattern. This moves CanvasPatternPaintStyle to LibGfx
so we don't have to reach into LibWeb, and implements the plumbing to
let Skia use images as a fill pattern.
2025-10-23 13:20:03 +01:00
Undefine
40bc1c0eb5 LibGfx: Enable Vulkan shared images and WebGL on FreeBSD 2025-10-22 13:54:54 +02:00
Undefine
bfa86f7961 LibGfx: Use PkgConfig to find libdrm
On FreeBSD the libdrm headers are not in a standard location so this
makes the include more portable.
2025-10-22 13:54:54 +02:00
Tim Ledbetter
7db73118e9 LibWeb+LibGfx: Draw shadows for stroke joins and caps 2025-10-21 18:55:08 +02:00
Tim Ledbetter
0516c414d4 LibWeb: Don't draw shadows for transparent gradient fills 2025-10-21 18:55:08 +02:00
aplefull
5df216218b LibGfx: Correctly determine when to invert CMYK
We should invert CMYK data only if color space is JCS_CMYK and either
there is no Adobe marker, or the Adobe transform is 0. Transform 2
indicates YCCK data, which we should not invert.
2025-10-15 21:50:16 +02:00
Tim Ledbetter
e55060ef6e LibWeb: Support the display-p3-linear color space in color functions 2025-10-15 18:40:48 +02:00
ayeteadoe
0d5136ae5c LibWeb: Add support for bitmap scaling in createImageBitmap() 2025-10-14 12:19:33 +02:00
Aliaksandr Kalenik
7ba34e8bd1 LibGfx: Implement AffineTransform::to_matrix() 2025-10-10 15:37:45 +02:00
Lorenz A
1e6ac54b75 LibGfx+LibWeb: Don't display Glyphs that are not on the path 2025-10-08 03:34:53 +01:00
Zaggy1024
1ae7ecc3e9 LibGfx: Free the harfbuzz buffer when measuring text width
I spotted this leak when WebContent was exiting with ASan enabled on a
page with a media element. MediaPaintable calls Gfx::Font::width(),
which calls through to measure_text_width(), which then drops an
hb_buffer_t* without freeing it.
2025-10-03 09:22:22 +02:00
aplefull
b3bdb202f8 LibGfx: Allow decoding of GIFs with empty LZW data
The decoder was requiring GIF files to be at least 32 bytes, but the
actual minimum for a valid GIF is only 26 bytes:
- 6 bytes for the header
- 7 bytes for the Logical Screen Descriptor
- 10 bytes for the Image Descriptor
- 2 bytes for the LZW minimum code size and block terminator
- 1 byte for the GIF trailer

This change allows us to load minimal 1x1 GIFs with empty LZW data.
They are commonly used on the web as transparent placeholders with
minimal file size.
2025-10-02 11:04:35 +02:00
Tim Ledbetter
a00e7cb20b LibWeb: Implement <feComposite> SVG filter 2025-09-30 22:33:12 +01: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
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
Aliaksandr Kalenik
2cf10981af LibGfx+LibWeb: Implement GlyphRun::bounding_rect()
Allows us to skip painting of glyph runs lying outside of viewport.
2025-09-23 17:55:32 +02:00
Andreas Kling
4eca3781c7 LibGfx: Add fast_is<T> optimization for Typeface and TypefaceSkia 2025-09-22 15:00:50 +02:00
Andreas Kling
66601f7d59 LibWeb: Cache results of harfbuzz text shaping
This patch introduces a per-Gfx::Font cache for harfbuzz text shaping
results. As long as the same OpenType features are used, we now cache
the results of harfbuzz shaping, saving massive amounts of time during
text layout.

As an example, it saves multiple seconds when loading the ECMAScript
specification at <https://tc39.es/ecma262>. Before this change, harfbuzz
shaping was taking up roughly 11% of a profile of loading that page.
The cache brings it down to 1.8%.

Note that the cache currently grows unbounded. I've left a FIXME about
adding some limits.
2025-09-21 13:22:38 +02:00
Andreas Kling
3dd700e4de LibWeb: Remove UTF-8 text shaping code path
We now only support the UTF-16 path. (Of course we still handle when
Utf16String is internally optimized with ASCII storage.)
2025-09-21 13:22:38 +02:00
Andreas Kling
b634918ff6 LibWeb: Remove Font::width() overloads for UTF-8
This is prep work for getting rid of UTF-8 text shaping.
2025-09-21 13:22:38 +02:00
Jelle Raaijmakers
c31eff6a47 Everywhere: Use Optional<T>::ensure() where useful
No functional changes.
2025-09-17 12:01:18 -04:00
Louis Dalibard
660bcfa2cd LibGfx+LibWeb+UI: Add OpenHand cursor for CSS grab property 2025-09-13 14:27:18 +02:00
Ali Mohammad Pur
4462348916 Everywhere: Slap some [[clang::lifetimebound]] where appropriate
This first pass only applies to the following two cases:
- Public functions returning a view type into an object they own
- Public ctors storing a view type

This catches a grand total of one (1) issue, which is fixed in
the previous commit.
2025-09-01 11:11:38 +02:00
Tim Ledbetter
d4f05bc4ef LibWeb: Implement <feImage> SVG filter 2025-08-29 10:15:24 +01:00
Andreas Kling
4350bccf8e LibWeb: Use Accelerate framework on macOS to premultiply bitmap data
This leverages hardware acceleration to speed things up considerably,
shaving ~500ms of load time off of https://cloudflare.com/
2025-08-23 14:09:17 +02:00
Andreas Kling
67432e35f1 LibGfx: Match vImage premultiply/unpremultiply rounding behavior
Our Color::to_premultiplied() and Color::to_unpremultiplied() used
integer truncation.

Apple’s Accelerate framework (and many other libraries) use
round-to-nearest, which avoids bias and produces results that differ
by ±1 in many cases.

This commit switches both helpers to round-to-nearest and clamps the
results to [0,255]. For alpha==0 we now return fully transparent black
(0,0,0,0) to align with common conventions, instead of preserving RGB.
2025-08-23 14:09:17 +02:00
Timothy Flynn
047f521c4c LibGfx+LibWeb: Add some extra fields to glyph run data
We currently have a mixup in LibWeb between code unit offset and glyph
offset during hit testing. These extra fields will allow us to correct
this discrepency.
2025-08-22 14:06:46 +02:00
Erik Kurzinger
ce03b8b3b1 LibGfx+LibWeb: Only compile dma-buf-related code on Linux
Shareable Vulkan image allocation on Linux relies on the dma-buf
interface, which is a Linux-specific thing. Therefore, we should only be
compiling it (and any code that uses it) on Linux. This change adds
preprocessor guards to do that. Enabling similar functionality on other
operating systems will need to leverage analogous interfaces on those
platforms, e.g. win32 handles on Windows.

All Vulkan image code will now be guarded by the USE_VULKAN_IMAGES
preprocessor definition, currently enabled on Linux if Vulkan is
available. Additionally, we shuffle around some code in
OpenGLContext.cpp to simplify the preprocessor conditionals.
2025-08-21 14:42:41 +02:00
Jamie Mansfield
97746fb574 LibGfx: Fix colour with Photoshop JPEG files using CMYK
This is based on the original functionality Lucus wrote prior to using
libjpeg.

Co-authored-by: Lucas CHOLLET <lucas.chollet@free.fr>
2025-08-20 12:04:39 +02:00
Aliaksandr Kalenik
2df0b6024f LibGfx: Use array_size() when possible in VulkanContext.cpp 2025-08-19 20:45:18 +02:00
Aliaksandr Kalenik
3ec37978e6 LibGfx: Use reinterpret_cast instead of C style in create_vulkan_context 2025-08-19 20:45:18 +02:00
Erik Kurzinger
41f1e920d8 LibGfx: Allow creating a PaintingSurface from a Vulkan image
This adds a new PaintingSurface creation function, create_from_vkimage,
which returns a PaintingSurface backed by a vulkan image. It's analogous
to the existing create_from_iosurface function. In both cases the
backing object will be imported into Skia as a render target and then an
SkSurface will be wrapped around that.

In order to ensure that the image will not be freed while still in use
by Skia, we will manually bump the refcount of the VulkanImage object
before passing it to Skia and then use the releaseCallback parameter of
WrapBackendRenderTarget to register a callback that drops this
reference.
2025-08-19 00:30:22 +02:00
Erik Kurzinger
08343970fb LibGfx: Save VulkanContext in SkiaBackendContext
This retains access to the vulkan device, queue, etc. handles which will
be needed for image allocation and possible other things in the future.
2025-08-19 00:30:22 +02:00
Erik Kurzinger
60a7359f0f LibGfx: Implement Vulkan image allocation
This introduces the ability to allocate Vulkan images which can be
shared across graphics APIs or across processes using the Linux dma-buf
interface.

The create_shareable_vulkan_image function takes a VulkanContext, image
width, height, and format, and an array of DRM format modifiers
representing image memory layouts accepted by the caller. The function
will intersect this list with the list of modifiers supported by the
Vulkan implementation, ensuring the resulting image uses one of those
layouts (exactly which one is up to the implementation). The function
will return a VulkanImage object, which is reference-counted and
encapsulates the VkImage itself as well as the backing memory
allocation. It also stores various image parameters such as usage,
tiling, etc.

The VulkanImage::get_dma_buf_fd function will create a file descriptor
representing the image's backing dma-buf which can then be imported by a
different API or sent over a unix domain socket.
2025-08-19 00:30:22 +02:00
Erik Kurzinger
06c916d91c LibGfx: Allocate command buffer for VulkanContext
A later change will add the ability to allocate images. We need a
command buffer in order to initialize the layout of those images.
2025-08-19 00:30:22 +02:00
Erik Kurzinger
1a6a114667 LibGfx: Save graphics queue family index in VulkanContext
This will be needed for image allocation, and anyway I think we're
supposed to be passing this to Skia during context creation.
2025-08-19 00:30:22 +02:00
Tim Ledbetter
ad06ac0d58 LibWeb: Implement the color-interpolation property for SVG gradients
This changes the operating color space for gradient `<linearGradient>`
and `<radialGradient>` elements.
2025-08-17 10:51:05 +02:00
norbiros
783ae44462 LibWeb: Fix color interpolation by premultiplying alpha
The current Color::interpolate_color method does not follow the specs
properly. Started improving it by handling premultiplied alpha in color
interpolation.

Only one WPT test covers this (color-transition-premultiplied), which we
currently pass due to a different approach in Color.mixed_with.
2025-08-14 11:09:05 +02:00
Callum Law
7182a537f3 LibWeb: Reduce inaccuracies when creating rotation matrices
When converting rotate transform functions `sin` and `cos` can sometimes
be inaccurate. To avoid these inaccuracies we:
 - Mod the angle to minimise inaccuracies in the first place.
 - Discard tiny (smaller than epsilon) values returned by `sin` and
   `cos` as inaccuracies.

This is in line with  other browsers (e.g. Gecko and WebKit).
2025-08-11 17:10:04 +01:00
Jelle Raaijmakers
85ad99b98a LibWeb: Implement <feMerge> SVG filter 2025-08-07 16:41:12 +02:00
Jelle Raaijmakers
1377dba7af LibWeb: Implement <feOffset> SVG filter 2025-08-07 16:41:12 +02:00
Tim Ledbetter
22225af994 LibGfx: Reorder CompositingAndBlendingOperator values
This change aligns blending operator values with the constants in
`SVGFEBlendElement`.
2025-08-06 15:21:03 +02:00
Timothy Flynn
d893d3234d LibGfx: Support UTF-16 SVG text placement 2025-08-05 15:13:36 +02:00
Jelle Raaijmakers
62cf33b98e LibGfx: Remove WebP animation writer and utility
This went unused.
2025-08-05 11:30:20 +02:00