summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx
AgeCommit message (Collapse)Author
2021-08-09Everywhere: Use tobyase@serenityos.org for my copyright headersTobias Christiansen
2021-08-08Userland: Use kmalloc_array() where appropriateAndreas Kling
2021-08-07LibGfx: Add alternate_color to draw_lineTobias Christiansen
This alternate_color can be used when drawing dashed lines to have two alternating Colors.
2021-08-01LibGfx: Fix writing PNG headers on x86_64Gunnar Beutner
m_data.size() returns a size_t which is a 64-bit type on x86_64. This resulted in us incorrectly using zero in the PNG header.
2021-08-01LibGfx: Fix a spelling mistake in a variable nameGunnar Beutner
2021-08-01LibGfx: Remove unused header includesBrian Gianforcaro
2021-07-30LibGfx: Refactor Point.constrain to use AKFrHun
2021-07-30LibGfx: Use correct variable size on bitmap to buffer convertionKarol Kosek
The issue was that size_in_bytes() returns size_t, but the buffer used a size of the unsigned for itself, which only matched on 32-bit systems and caused an assert error otherwise. This fixes a crash on drag in FileManager on non 32-bit systems!
2021-07-29LibTTF/LibGfx: Remove circular dependency by merging LibTTF into LibGfxAndrew Kaster
LibTTF has a concrete dependency on LibGfx for things like Gfx::Bitmap, and LibGfx has a concrete dependency in the TTF::Font class in Gfx::FontDatabase. This circular dependency works fine for Serenity and Lagom Linux builds of the two libraries. It also works fine for static library builds on Lagom macOS builds. However, future changes will make Lagom use shared libraries, and circular library dependencies are not tolerated in macOS.
2021-07-28LibGUI+LibGfx: Highlight currently active tab button with accent colorAndreas Kling
Use the new "Accent" color role to emphasize the currently active tab within a GUI::TabWidget. :^)
2021-07-28LibGfx+Base: Add a themable "Accent" color roleAndreas Kling
This can be used by GUI widgets to draw attention to a specific part of the widget, for example the currently active sub-widget component.
2021-07-28LibGfx: Remove unused StylePainter::paint_surface()Andreas Kling
2021-07-27LibGfx: Take the glyph spacing into account when building a linesin-ack
Without this, a word might be added to a line despite going outside the rect, due to the glyph spacing between blocks not being considered.
2021-07-27LibGfx: Remove extra space considered during wrappingsin-ack
This was previously required because the whitespace was consumed and manually added back after the fact, but now that we preserve whitespace, this breaks wrapping of text with whitespace after it.
2021-07-27LibGfx: Hotfix a -Wmaybe-uninitialized failure on the build botsAndreas Kling
2021-07-27LibGfx: Make TextLayout algorithm whitespace-awaresin-ack
This converts the TextLayout algorithm from handling just words to handling blocks of strings. With this model, whitespace is preserved and inserted as-is, rather than being eaten and then replaced with a single space (or none, if the whitespace was at the start of the word). Closes #9032.
2021-07-27Userland: Make TextWrapping::Wrap opt-insin-ack
This was breaking many places which didn't expect text to wrap. Now, the only place where text currently wraps is in GUI::Label.
2021-07-27LibGfx: Remove Gfx::ImageDecoder::bitmap() in favor of frame(index)Andreas Kling
To transparently support multi-frame images, all decoder plugins have already been updated to return their only bitmap for frame(0). This patch completes the remaining cleanup work by removing the ImageDecoder::bitmap() API and having all clients call frame() instead.
2021-07-27LibGfx: Improve ImageDecoder constructionAndreas Kling
Previously, ImageDecoder::create() would return a NonnullRefPtr and could not "fail", although the returned decoder may be "invalid" which you then had to check anyway. The new interface looks like this: static RefPtr<Gfx::ImageDecoder> try_create(ReadonlyBytes); This simplifies ImageDecoder since it no longer has to worry about its validity. Client code gets slightly clearer as well.
2021-07-26LibGfx: Add FastBoxBlurFilterTobias Christiansen
This patch adds a FastBoxBlurFilter to the system. It can be created by specifying a Bitmap it will work on. There are two uses implemented: - apply_single_pass() applys an implementation of a linear-time box-blur algorithm with the specified radius using a horizontal and a vertical pass and utilizinga sliding window. - apply_three_passes() gets a better Gaussian approximation by applying the filter three times. For this to work the radius of each pass is calculated to fit Gauss the best.
2021-07-26Userland: Move text wrapping/elision into the new TextLayout :^)sin-ack
This class now contains all the fun bits about laying out text in a rect. It will handle line wrapping at a certain width, cutting off lines that don't fit the given rect, and handling text elision. Painter::draw_text now internally uses this. Future work here would be not laying out text twice (once actually preparing the lines to be rendered and once to get the bounding box), and possibly adding left elision if necessary. Additionally, this commit makes the Utf32View versions of Painter::draw_text convert to Utf8View internally. The intention is to completely remove those versions, but they're kept at the moment to keep the scope of this PR small.
2021-07-25Kernel: Make purgeable memory a VMObject level concept (again)Andreas Kling
This patch changes the semantics of purgeable memory. - AnonymousVMObject now has a "purgeable" flag. It can only be set when constructing the object. (Previously, all anonymous memory was effectively purgeable.) - AnonymousVMObject now has a "volatile" flag. It covers the entire range of physical pages. (Previously, we tracked ranges of volatile pages, effectively making it a page-level concept.) - Non-volatile objects maintain a physical page reservation via the committed pages mechanism, to ensure full coverage for page faults. - When an object is made volatile, it relinquishes any unused committed pages immediately. If later made non-volatile again, we then attempt to make a new committed pages reservation. If this fails, we return ENOMEM to userspace. mmap() now creates purgeable objects if passed the MAP_PURGEABLE option together with MAP_ANONYMOUS. anon_create() memory is always purgeable.
2021-07-25LibGfx: Make Gfx::Bitmap::set_nonvolatile() report allocation failureAndreas Kling
Making a bitmap non-volatile after being volatile may fail to allocate physical pages after the kernel stole the old pages in a purge. This is different from the pages being purged, but reallocated. In that case, they are simply replaced with zero-fill-on-demand pages as if they were freshly allocated.
2021-07-25LibGfx: Remove "purgeable Gfx::Bitmap" as a separate conceptAndreas Kling
This was a really weird thing to begin with, purgeable bitmaps were basically regular bitmaps without a physical memory reservation. Since all the clients of this code ended up populating the bitmaps with pixels immediately after allocating them anyway, there was no need to avoid the reservation. Instead, all Gfx::Bitmaps are now purgeable, in the sense that they can be marked as volatile or non-volatile. The only difference here is that allocation failure is surfaced when we try to create the bitmap instead of during the handling of a subsequent page fault.
2021-07-25LibGfx: Add try_ prefix to Bitmap::try_allocate_backing_store()Andreas Kling
2021-07-22LibGfx: Implement Color::from_hsl/hsla()Sam Atkins
This is required by CSS, and implemented based on the CSS standard's algorithm.
2021-07-22LibGfx: Use calloc() instead of malloc()+memset() Gfx::BitmapFontAndreas Kling
2021-07-21LibGfx: Sprinkle [[nodiscard]] on Gfx::BitmapAndreas Kling
2021-07-21LibGfx: Use "try_" prefix for static factory functionsAndreas Kling
Also mark them as [[nodiscard]].
2021-07-21LibGfx: Add an algorithm to disperse overlapping rectanglesTom
2021-07-20LibTTF+LibGfx: Make Gfx::Font::bold_variant() work for TTF fontsAndreas Kling
There's no need for this to be a virtual, it's just a font database lookup and can be done in the Font base class.
2021-07-20LibTTF+LibGfx: Improve vertical alignment of glyphsAndreas Kling
Before this patch, some glyphs had a weird off-by-1 vertical position which looked really jarring at small font sizes. This was caused by glyph bitmaps having different heights from each other. (Each glyph bitmap was minimally sized to fit only the glyph itself, and then vertically positioned during the paint phase. Since this vertical positioning was integer based, subpixel precision was lost and things ended up looking wonky.) Fix this by making all glyph bitmaps be the same height so we can blit them at the same integer y position. We use the typographic ascent from the OS/2 table to transform the glyph coordinates. The end result is a huge improvement visually. :^)
2021-07-19Everywhere: Use AK/Math.h if applicableHendiadyoin1
AK's version should see better inlining behaviors, than the LibM one. We avoid mixed usage for now though. Also clean up some stale math includes and improper floatingpoint usage.
2021-07-15LibGUI: Dither pattern should be independent from clipping rectangleTom
The dither pattern needs to be determined relative to the bitmap itself, not the clipping rectangle. Fixes #8780
2021-07-14LibGfx: Don't underline escaped ampersand in menusKarol Kosek
Double ampersands (&&) marking in menus is meant to provide a way to show the ampersand, since using just one would turn it into a modifier that sets the shortcut for the next character. Unfortunately, while the first character had a special case to avoid marking this set, the marking was still calculated for the second character. The fix is rather simple: just skip then the following character! This issue applied only to the visual part of the Menu. The WindowServer calculation for the shortcut character is working properly, i.e. ignores escaped ampersands.
2021-07-14LibGfx: Use clear_with capacity instead of clear in PNGWriterAziz Berkay Yesilyurt
Same vector was cleared up and filled in continuously.
2021-07-14LibGfx: Store the size of the chunk from start in PNGWriterAziz Berkay Yesilyurt
Before this change PNGWriter::add_chunk used to make a copy of PNGChunk's ByteBuffer to prepend the size of the data. With this change, 4-byte space is saved from the beginning and written at the end of the operation. Avoiding this copy yields significant speed up.
2021-07-14LibGfx: Prevent a copy in PNGWriter by storing type data at startAziz Berkay Yesilyurt
2021-07-14LibGfx: Prevent frequent memory allocations in PNGWriterAziz Berkay Yesilyurt
2021-07-14LibGfx: Use ByteBuffer instead of Vector<u8> in PNGWriterAziz Berkay Yesilyurt
This is the first step towards reducing the number of copies in PNGWriter by switching to ByteBuffer as underlying storage.
2021-07-11LibGfx: Try to get TTF font when query is not in name->font mapLuK1337
This change allows us to select TTF fonts in display settings again :^)
2021-07-09LibGfx: Improve Painter::draw_line() alignment with (thickness > 1)Andreas Kling
Thicker lines are drawn by filling rectangles along the path. Previously these rectangles used the points as their top left corner. This patch changes it to use the points as the center of the rectangles which makes the PixelPaint line tool feel a lot more natural. :^)
2021-07-09LibGfx: Add "override" declarations and use east const in BitmapFont.hMax Wipfli
2021-07-09LibGfx: Optimize BitmapFont::unicode_view_width() a bitMax Wipfli
This optimizes the method to no longer compare if width > longest_width on every iteration, since it's only required on CR/LF or at the end.
2021-07-09LibGfx: ALWAYS_INLINE BitmapFont::unicode_view_widthMax Wipfli
This adds the ALWAYS_INLINE attribute to unicode_view_width. Also, it cleans up the BitmapFont::view() code a little bit. This should help performance of this hot code. Because the call to the width() methods is a virtual dispatch, it doesn't help to inline the width() methods themselves.
2021-07-09LibGfx: Remove unused headers from BitmapFont.{cpp,h}Max Wipfli
2021-07-09LibGfx: Make enclosing_int_rect(FloatRect) actually enclose the rectAndreas Kling
2021-07-08Everywhere: Don't promote float to double where not neededDaniel Bertalan
The `float => double => float` round trip seen in a couple of places might pessimize the code. Even if it's truncated to an int in the end, it's weird not to use the functions with the `f` suffixes when working with single precision floats.
2021-07-08AK+Userland: Add generic `AK::abs()` function and use itDaniel Bertalan
Previously, in LibGFX's `Point` class, calculated distances were passed to the integer `abs` function, even if the stored type was a float. This caused the value to unexpectedly be truncated. Luckily, this API was not used with floating point types, but that can change in the future, so why not fix it now :^) Since we are in C++, we can use function overloading to make things easy, and to automatically use the right version. This is even better than the LibC/LibM functions, as using a bit of hackery, they are able to be constant-evaluated. They use compiler intrinsics, so they do not depend on external code and the compiler can emit the most optimized code by default. Since we aren't using the C++ standard library's trick of importing everything into the `AK` namespace, this `abs` function cannot be exported to the global namespace, as the names would clash.
2021-07-07LibGfx: BitmapFont: Handle '\r' and '\n' when calculating text widthLuK1337
Previously calculating multiline text width would return invalid value, this change makes it so that we are returning the longest line width. We are now also reusing same width() implementation for both UTF-8 and UTF-32 strings.