Commit graph

564 commits

Author SHA1 Message Date
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
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
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
Idan Horowitz
e81c33da42 LibGfx: Skip manual cropping for the degenerate case 2025-08-04 23:39:11 +02:00
Idan Horowitz
3c3da1ce8c LibGfx: Allow specifying outside color in Bitmap::cropped()
This is required for LibWeb bitmap cropping.
2025-08-04 23:39:11 +02:00
Idan Horowitz
bf2dc77dfc LibGfx: Remove unused new bitmap format option from Bitmap::cropped() 2025-08-04 23:39:11 +02:00
Callum Law
8a4e9f571f LibWeb: Respect letter-spacing for last glyph of each chunk
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Previously we would omit the letter spacing for the end glyph of each
chunk in a misguided attempt to conform to the spec's instruction that
we "really should not append letter spacing to the right or trailing
edge of a line", this behaviour can be removed entirely as other
browsers (Firefox, Chrome) don't implement it either.
2025-08-03 22:23:34 +02:00
Aliaksandr Kalenik
41e3ddb7fa LibGfx+LibWeb: Remove aa_translation from StrokePath and FillPath
`aa_translation` is something we inherited from times when
AntiAliasingPainter was a thing. This change replaces it by applying
offset directly to path.
2025-08-03 10:42:33 +02:00
Aliaksandr Kalenik
1001ff2599 LibGfx+LibWeb: Delete unused PaintStyle::paint() implementations
These are unused since we moved to Skia and it's misleading to keep
them around.
2025-08-01 04:39:50 -04:00
Timothy Flynn
f3146d3320 LibGfx: Implement a UTF-16 Color stringifier 2025-07-28 12:25:11 +02:00
Arran Ireland
9a8599f265 LibGfx+LibMedia+LibWeb: Use new Matrix subscript operator 2025-07-28 09:15:23 +02:00
Arran Ireland
423e944a92 LibGfx+LibWeb: Upgrade to multi-arg subscript operator in Matrix
See the following for more details:
https://en.cppreference.com/w/cpp/language/operators.html#Array_subscript_operator
2025-07-28 09:15:23 +02:00
Rocco Corsi
d322c3a21f LibGfx: VulkanContext coverity reports integer_overflow on index
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Coverity static analysis reports that the code that scans the queue
families for one that has the graphics bit, can be -1 if none are
found, which could cause a problem when the -1 (signed) value is
used later as an index in a uint32_t (unsigned) variable.

Its not immediately clear how often this could occur, not finding
a queue family with the graphics bit, but adding some protecting
just in case.
2025-07-27 23:38:49 -04:00
Timothy Flynn
0e9b694058 LibGfx: Support UTF-16 text shaping
We can achieve this with templating the string view type, and then just
piping the view into the correct `hb_buffer_add_utf*` API.
2025-07-25 18:16:22 +02:00
Jelle Raaijmakers
a9862d60bf LibGfx: Add Color::from_utf16_string() 2025-07-24 07:18:25 -04:00
Kenneth Myhra
09f336bf8f LibGfx: Use static_cast instead of C-style cast 2025-07-20 12:30:43 +12:00
Jelle Raaijmakers
0f642ecb5c LibGfx: Replace Bitmap::visually_equals() with ::diff()
This produces more granural information on the actual pixel errors
present between two bitmaps. It now also asserts that both bitmaps are
the same size, since we should never compare two differently sized
bitmaps anyway.
2025-07-17 12:59:11 +01:00
Jelle Raaijmakers
144eac44fb LibGfx: Remove Font::pixel_size_rounded_up()
The remaining callsites were removed in the previous commit.
2025-07-15 19:05:36 +01:00
Andreas Kling
a4fb21308d LibWeb: Don't add range data for FontCascadeList with no Unicode ranges
This fixes a bunch of WPT crashes in /html/canvas/offscreen/text/
2025-07-15 10:06:10 +02:00
Andreas Kling
0fece0650e LibGfx: Let FontCascadeList quickly reject out-of-range code points
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
By keeping track of the enclosing range around all Unicode ranges of a
FontCascadeList entry, we can quickly reject any code point that's
outside all ranges.

This knocks font_for_code_point() from 7% to 3% in the profile when
scrolling on https://screenshotone.com/
2025-07-14 19:05:25 +02:00
Lucien Fiorini
635adc8aa7 LibWeb/SVG: Implement resolution for a subset of SVG filters 2025-07-09 18:07:12 +01:00
Aliaksandr Kalenik
c18314b942 LibWeb+LibGfx: Replace BackingStore with PaintingSurface
Now, when Skia backend context is available by the time backing stores
are allocated, there is no need to have a separate BackingStore class.

This allows us to get rid of BackingStore -> PaintingSurface cache.
2025-07-04 16:12:47 +02:00
ayeteadoe
d897bfae91 CMake: Rename all_generated target to better convey intent 2025-07-03 23:19:41 +02:00
ayeteadoe
25f5936dee CMake: Rename serenity_* helper functions/macros to ladybird_* 2025-07-03 23:19:41 +02:00
Timothy Flynn
62d9a84b8d AK+Everywhere: Replace custom number parsers with fast_float
Some checks failed
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Build Dev Container Image / build (push) Has been cancelled
Our floating point number parser was based on the fast_float library:
https://github.com/fastfloat/fast_float

However, our implementation only supports 8-bit characters. To support
UTF-16, we will need to be able to convert char16_t-based strings to
numbers as well. This works out-of-the-box with fast_float.

We can also use fast_float for integer parsing.
2025-07-03 09:51:56 -04:00
Jelle Raaijmakers
180bb0fc5d Everywhere: Remove LibRIFF 2025-07-02 12:01:12 +01:00
ayeteadoe
2119ea982e LibGfx: Enable in Windows CI 2025-06-26 19:35:14 -06:00
Jelle Raaijmakers
2687246808 LibGfx: Use NonnullRefPtr<Bitmap> for frame descriptors
Some checks are pending
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This makes it a bit easier to reason about where bitmaps should be
available.
2025-06-25 22:54:48 +12:00
Tim Ledbetter
e69d9fb331 LibGfx: Destroy FontConfig string iterator after use
This avoids a memory leak in `FontDatabase::font_directories()`.
2025-06-25 08:59:49 +02:00
Sam Atkins
423cdd447d LibWeb+LibGfx: Apply editorial punctuation/whitespace/markup fixes
Corresponds to d426109ea1
and fd08f81d06
2025-06-25 03:12:19 +12:00
Tom Lynch
b3d459f4de LibGfx: Nearest neighbor scaling for ScalingMode::SmoothPixels 2025-06-23 16:05:52 +02:00
Luke Wilde
ffae0d8b2d LibGfx/AVIF: Always reduce decoding output to a bit depth of 8
Gfx::Bitmap only supports a bit depth of 8, therefore we refused to
load AVIF images which didn't have this bit depth.

However, we can tell the libavif decoder to reduce the output depth by
setting avifRGBImage.depth to 8. This allows us to support any input
depth.

Makes images load on https://www.ikea.com/ which uses Cloudflare Images
to re-encode their images to 16-bit AVIF.
2025-06-18 14:27:24 +02:00
Colin Reeder
d4a5d16d27 LibGfx: Explicitly link against fontconfig 2025-06-17 16:55:50 -06:00