Commit graph

193 commits

Author SHA1 Message Date
MacDue
b1a72d66f6 LibGfx: Speed up fill_path() with per scanline clipping & fast fills
This improves fill_path() performance by adding an API to the painter
that allows painting an entire scanline rather than just a pixel.
With this paths can be clipped a scanline at a time rather than each
pixel, removing a fair amount of checks.

Along with optimized clipping, this can now use a fast_u32_fill() to
paint all but the subpixels of a scanline if a solid color with no
alpha channel is used (which is quite common in SVGs).

This reduces scrolling around on svg.html from 21% in set_pixel() and
19% in fill_path() to just 7.8% in fill_path (with set_pixel()
eliminated). Now fill_path() is far from the slowest code when
scrolling the page.
2023-03-11 18:34:26 +00:00
Andreas Kling
8a48246ed1 Everywhere: Stop using NonnullRefPtrVector
This class had slightly confusing semantics and the added weirdness
doesn't seem worth it just so we can say "." instead of "->" when
iterating over a vector of NNRPs.

This patch replaces NonnullRefPtrVector<T> with Vector<NNRP<T>>.
2023-03-06 23:46:35 +01:00
Andreas Kling
552895da60 LibGfx: Skip old-style emoji lookup for fonts that have color bitmaps
Ultimately, we should find a way to route all emoji access through
the font code, but for now, this patch adds a special case for fonts
that are known to have embedded color bitmaps so we can test them.
2023-03-06 10:52:55 +01:00
Andreas Kling
e8cc1a4373 LibGfx: Prepare the paint code for fonts whose glyphs are color bitmaps
This patch does three things:
- Font::has_color_bitmaps() (true if CBLC and CBDT are present)
- Glyph now knows when its bitmap comes from a color bitmap font
- Painter draws color bitmap glyphs with the appropriate scaling etc
2023-03-06 10:52:55 +01:00
Andreas Kling
508fb7e1e9 Userland: Use Font::pixel_size_rounded_up() in more places 2023-03-04 00:29:38 +01:00
Timothy Flynn
62f2f0a081 LibGfx: Handle multi-code point emoji widths when drawing text runs
This API is used by LibWeb's text painter. Bring it up to date with the
glyph width computations performed in draw_text_line() used by other GUI
applications.
2023-03-02 18:33:44 +01:00
Timothy Flynn
e231f72f61 LibGfx: Render text presentation emoji as text if we have its glyph 2023-02-28 13:22:58 +00:00
Aliaksandr Kalenik
87fa1c5e66 Revert "LibWeb: Fix clip of hidden overflow..."
This reverts commit eb1ef59603c13c43b87c099c43c4d118dc8441f6.

The idea of saving clip box to apply it to handle `overflow: hidden`
turned out to break painting if box is painted before it's containing
block (it is possible if box has negative z-index).
2023-02-24 20:55:40 +01:00
Timothy Flynn
36a495e87e LibGfx: Use non-emoji glyph width API to compute the width of a space 2023-02-24 20:28:23 +01:00
Timothy Flynn
8be43cd3bf LibGfx: Use LibUnicode to filter code points that cannot start an emoji 2023-02-24 19:48:47 +01:00
Timothy Flynn
2bc7c11e8d LibGfx: Consult Unicode data to decode emoji sequences
For example, consider the Pirate Flag emoji, which is the code point
sequence U+1F3F4 U+200D U+2620 U+FE0F. Our current emoji resolution does
not consider U+200D (Zero Width Joiner) as part of an emoji sequence.
Therefore fonts like Katica, which have a glyph for U+1F3F4, will draw
that glyph without checking if we have an emoji bitmap.

This removes some hard-coded code points and consults the UCD's code
point properties for emoji sequence components and variation selectors.
This recognizes the ZWJ code point as part of an emoji sequence.
2023-02-22 10:14:36 +01:00
Timothy Flynn
b823f3d29f LibGfx: Consider multi-code point glyphs when computing text width
Currently, we compute the width of text one code point at a time. This
ignores grapheme clusters (emoji in particular). One effect of this is
when highlighting a multi-code point emoji. We will errantly increase
the highlight rect to the sum of all code point widths, rather than
just the width of the resolved emoji bitmap.
2023-02-22 10:14:36 +01:00
Andreas Kling
7c607462a4 LibGfx+LibWeb: Store radii as FloatSize rather than FloatPoint
Radii are sizes, not points. This becomes important when mapping them
through a 2D transform.
2023-02-10 23:33:16 +01:00
Andreas Kling
e9078e216d LibGfx: Make sure the Painter clip rect is never larger than the target
The new Painter::set_clip_rect(IntRect) API was able to make the clip
rect larger than the underlying target bitmap. This was not good, as it
could make it possible to draw outside the bitmap memory.

Fixes a crash when viewing https://twinings.co.uk/ in the browser. :^)
2023-02-10 23:33:16 +01:00
Tim Ledbetter
392dac0818 LibGfx: Make checkerboard patterns static when panning
Previously checkerboard patterns were anchored to the top left of the
bitmap they were being drawn into.

This makes the transparency grid in PixelPaint static relative to the
canvas when panning.
2023-02-08 21:53:34 +01:00
MacDue
63b11030f0 Everywhere: Use ReadonlySpan<T> instead of Span<T const> 2023-02-08 19:15:45 +00:00
Nico Weber
c8832807d6 LibGfx+Tests: Remove code unnecessary after 9e7c16d0a4 2023-02-01 08:56:56 -05:00
MacDue
f3c0987afe LibGfx: Add Painter::fill_rect(rect, paint_style)
The usual fill_rect()... but with style :^)
2023-01-22 18:15:52 +01:00
MacDue
223cedc896 LibGfx: Update fill_path() to support taking a PaintStyle
This means fill_path() now paints the scanlines its self rather than
calling draw_line() which easily allows each pixel along the scanline
to have a different color.
2023-01-22 18:15:52 +01:00
Arda Cinar
9418586990 LibGfx: Remove an unnecessary FIXME
Clipping in diagonal line drawing has already been implemented a long
time ago.
2023-01-17 22:54:18 +01:00
Arda Cinar
c8d7bf5449 LibGfx: Implement drawing dotted/dashed diagonal Lines
The implementation simply tracks the number of pixels we have drawn so
far and draws pixels in an on-and-off pattern
2023-01-17 22:54:18 +01:00
MacDue
c8c065b6b0 LibWeb+LibGfx: Migrate (most of) the CSS gradient painting to LibGfx
This moves the CSS gradient painting to the painter creating:

 - Painter::fill_rect_with_linear_gradient()
 - Painter::fill_rect_with_conic_gradient()
 - Painter::fill_rect_with_radial_gradient()

This has a few benefits:
 - The gradients can now easily respect the painter scale
 - The Painter::fill_pixels() escape hatch can be removed
 - We can remove the old fixed color stop gradient code
    - The old functions are  now just a shim
 - Anywhere can now easily use this gradient painting code!

This only leaves the color stop resolution in LibWeb (which is fine).
Just means in LibGfx you have to actually specify color stop positions.

(Also while here add a small optimization to avoid generating
excessively long gradient lines)
2023-01-10 10:25:58 +01:00
Andreas Kling
b2d3ceaec5 LibGfx: Make text painting better at aligning vector fonts vertically
This is achieved by simplifying the logic in TextLayout. We get rid
of all the various ways that the layout bounding rect can get cropped.
Then we make sure to use the right pixel metrics.

Finally we use the font's own line gap metrics instead of hard-coding 4.

The end result is that text painted with vector fonts now gets pretty
reasonable vertical alignment in most cases.
2023-01-06 12:02:21 +01:00
Andreas Kling
d2195f8088 LibGfx: Use Gfx::Rect::align_within() to simplify text drawing logic
Instead of doing this manually, just use the helper we already have.
2023-01-06 12:02:20 +01:00
Andreas Kling
6b421fb521 LibGfx: Slim down Gfx::TextLayout API by removing unused accessors
Also store the Font as a const reference instead of a raw pointer,
since we don't allow a null Font here.
2023-01-06 12:02:20 +01:00
MacDue
6632023498 LibGfx: Enable subpixel accurate text rendering in Painter::draw_text()
This improves kerning and alignment jittering quite a bit :^)
2023-01-05 12:09:35 +01:00
MacDue
a1726b1ba5 LibGfx: Avoid rounding/truncating glyph positions till blitting
This keeps some overloads that accept ints to avoid adding calls to
.to_type<float>() all over the place.
2023-01-05 12:09:35 +01:00
Lucas CHOLLET
2eeaba3f1d LibGfx: Use the Midpoint Ellipse Algorithm for filled ellipses 2023-01-03 17:58:11 +01:00
Lucas CHOLLET
d2372464a2 LibGfx: Put the Midpoint Ellipse Algorithm in its own function 2023-01-03 17:58:11 +01:00
Andreas Kling
555d7a6fce LibGfx: Make Font::glyph_width*() APIs return float 2023-01-03 15:25:02 +01:00
Andreas Kling
3407ab0fd1 LibGfx: Make Font::width() return a float 2023-01-03 15:25:02 +01:00
Andreas Kling
bfa7381852 LibGfx: Make Font::pixel_size() return a float
Here's yet another place where we were chopping of decimals.
2023-01-03 15:25:02 +01:00
MacDue
ca01017f32 LibGfx: Add Painter::fill_pixels()
This function fills a region of pixels with the result of a callback
function. This is an alternative to a for loop that repeatedly calls
Painter::set_pixel(), which can get very expensive due to the clipping
checks set_pixel() does each call.
2022-12-25 15:35:31 +01:00
FrHun
df30440117 LibGfx: Add NearestFractional scaling type to painter
This is useful for cases where you want to avoid scaling artifacts.
2022-12-23 12:16:46 +00:00
MacDue
6c27f2c071 LibGfx: Don't blend opaque pixels 2022-12-20 11:03:18 +01:00
Sam Atkins
83f31cb4a7 LibGfx: Add int overloads for (AntiAliasing)Painter float methods
Without this change, the upcoming LibWeb pixel types will require a
silly doubled conversion in some places.

eg: `some_rect.to_type<int>().to_type<float>()`

With these overloads, we can get away with `some_rect.to_type<int>()`.
2022-12-08 12:46:03 +00:00
MacDue
27fae78335 Meta+Userland: Pass Gfx::IntSize by value
Just two ints like Gfx::IntPoint.
2022-12-07 11:48:27 +01:00
MacDue
e011eafd37 Meta+Userland: Pass Gfx::FloatPoint by value
Just a small 8-byte value like Gfx::IntPoint.
2022-12-07 11:48:27 +01:00
MacDue
7be0b27dd3 Meta+Userland: Pass Gfx::IntPoint by value
This is just two ints or 8 bytes or the size of the reference on
x86_64 or AArch64.
2022-12-07 11:48:27 +01:00
MacDue
bbc149ebb9 Meta+Userland: Pass Gfx::Color by value
Gfx::Color is always 4 bytes (it's just a wrapper over u32) it's less
work just to pass the color directly.

This also updates IPCCompiler to prevent from generating
Gfx::Color const &, which makes replacement easier.
2022-12-07 11:48:27 +01:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
lanmonster
2b7aa4a971 LibGfx+LibGUI: Use constant for line spacing instead of magic number 2022-11-30 07:57:21 +01:00
MacDue
0e65de2e11 LibGfx: Don't write blended pixel if the alpha is zero 2022-11-29 11:08:50 +01:00
Lucas CHOLLET
4219d50a21 LibGfx: Use the Midpoint Ellipse Algorithm
It is only used to draw non-antialiased and non-filled ellipses.
2022-11-26 00:49:05 +01:00
jack gleeson
4bf587811f PixelPaint+LibGfx: Allow resizing images and layers
This PR adds resize ability to PixelPaint as per issue 11862.
The previous behaviour was to always rescale the canvas when
resizing an image. This adds a checkbox to toggle between
rescaling, and resizing which blits the existing canvas to
the top left of the new, resized canvas.

As part of this, a new ScalingMode is added to
LibGfx - None.
2022-11-02 10:59:18 +00:00
Nico Weber
2af028132a AK+Everywhere: Add AK_COMPILER_{GCC,CLANG} and use them most places
Doesn't use them in libc headers so that those don't have to pull in
AK/Platform.h.

AK_COMPILER_GCC is set _only_ for gcc, not for clang too. (__GNUC__ is
defined in clang builds as well.) Using AK_COMPILER_GCC simplifies
things some.

AK_COMPILER_CLANG isn't as much of a win, other than that it's
consistent with AK_COMPILER_GCC.
2022-10-04 23:35:07 +01:00
Andreas Kling
b52165c5d7 LibWeb+LibGfx: Move the blit image through 2D transfrom to Gfx::Painter
Even though this code is obnoxiously slow, it still belongs in LibGfx
and should not be hidden away in LibWeb's CanvasRenderingContext2D.
2022-09-24 13:00:53 +02:00
MacDue
60356c8dde LibGfx: Support getting a bitmap for a region of painter
This will be needed so we can apply filter effects to the backdrop
of an element in LibWeb.

This now also allows getting a crop of a bitmap in a different format
than the source bitmap. This is for if the painter's bitmap does not
have an alpha channel, but you want to ensure the cropped bitmap does.
2022-09-16 10:50:48 +01:00
Jelle Raaijmakers
bfb4e08612 LibGfx: Use memcpy instead of fast_u32_copy for blitting
In some artificial full screen blitting profiling, I've seen `memcpy`
take up about 4% fewer samples each time I measure. It seems like
`fast_u32_copy` is not as fast as it'd like to believe.
2022-09-14 17:17:19 +02:00